gpt4 book ai didi

spring-boot - 停止使用 Stream 监听器的消息

转载 作者:行者123 更新时间:2023-12-05 00:58:01 24 4
gpt4 key购买 nike

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

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

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

我已经用谷歌搜索过了,但现在仍然不知道如何停止消费。有谁知道吗?

最佳答案

您可以使用执行器执行此操作(参见 Binding Visualization and Control)。或者您可以通过编程方式调用端点。

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

}

关于spring-boot - 停止使用 Stream 监听器的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58795176/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com