Stop consume message for Stream listener

为君一笑 提交于 2020-05-06 19:12:32

问题


I am looking for a way to stop consume messages with stream listener.

@StreamListener(MBinding.M_INPUT)
    public void consumeMessage(Message<MerchantEvent> message) {
    //handle when receive message
 }

cloud:
        stream:
            bindings:
                MInput:
                    destination: topicName
                    group: groupName

I have googled it but right now still have no idea how to stop consuming. Is there anyone who know it?


回答1:


You can do it using the actuator (see Binding Visualization and Control). Or you can invoke the endpoint programmatically.

@SpringBootApplication
@EnableBinding(Sink.class)
public class So58795176Application {

    public static void main(String[] args) {
        SpringApplication.run(So58795176Application.class, args);
    }

    @StreamListener(Sink.INPUT)
    public void listen(String in) {
        System.out.println();
    }

    @Autowired
    BindingsEndpoint endpoint;

    @Bean
    public ApplicationRunner runner() {
        return args -> {
            System.in.read();
            endpoint.changeState("input", State.STOPPED);
            System.in.read();
            endpoint.changeState("input", State.STARTED);
        };
    }

}


来源:https://stackoverflow.com/questions/58795176/stop-consume-message-for-stream-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!