[英]How to start and stop a google pubsub subsriber in spring boot app?
I have implemented a google pubsub topic-subscriber (spring-boot and cloud stream framework) using the spring.io guides example.我已经使用 spring.io 指南示例实现了一个 google pubsub 主题订阅者(spring-boot 和 cloud stream 框架)。
App starts consuming the messages as soon as the app is up.一旦应用程序启动,应用程序就会开始使用消息。 I would like to implement an api where we start and stop the consumption of messages on demand.
我想实现一个 api,我们可以在其中开始和停止按需消费消息。
Let's say GET /pubsub/messages -> start the subscriber -> gets messages (synchronous or asynchronous) -> stops the subscriber.假设 GET /pubsub/messages -> 启动订阅者 -> 获取消息(同步或异步) -> 停止订阅者。
Any thoughts would be helpful.任何想法都会有所帮助。
See this answer Stop consume message for Stream listener看到这个答案Stop consume message for Stream listener
You need to add the actuator Boot starter and inject the BindingsEndpoint
to stop/start the binding.您需要添加执行器 Boot starter 并注入
BindingsEndpoint
以停止/启动绑定。
You can set autoStartup
to false to prevent the binding from starting immediately.您可以将
autoStartup
设置为 false 以防止绑定立即开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.