停止使用 Stream 侦听器的消息 [英] Stop consume message for Stream listener

查看:33
本文介绍了停止使用 Stream 侦听器的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来停止使用流侦听器消费消息.

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?

推荐答案

您可以使用执行器来完成(请参阅 绑定可视化和控制).或者,您可以以编程方式调用端点.

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);
        };
    }

}

这篇关于停止使用 Stream 侦听器的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆