英文:
How to start and stop a google pubsub subsriber in spring boot app?
问题
我已经使用spring.io指南的示例,实现了一个使用spring-boot和cloud stream框架的Google Pub/Sub主题订阅器。
应用程序在启动后立即开始消费消息。我想实现一个API,在这个API上可以根据需要启动和停止消息的消费。
假设有一个GET /pubsub/messages的端点,调用它会启动订阅器,然后获取消息(同步或异步),最后停止订阅器。
欢迎提出任何想法。
英文:
I have implemented a google pubsub topic-subscriber (spring-boot and cloud stream framework) using the spring.io guides example.
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.
Let's say GET /pubsub/messages -> start the subscriber -> gets messages (synchronous or asynchronous) -> stops the subscriber.
Any thoughts would be helpful.
答案1
得分: 1
请参阅此答案 https://stackoverflow.com/questions/58795176/stop-consume-message-for-stream-listener
您需要添加执行器 Boot starter 并注入 BindingsEndpoint
以停止/启动绑定。
您可以将 autoStartup
设置为 false 以防止绑定立即启动。
英文:
See this answer https://stackoverflow.com/questions/58795176/stop-consume-message-for-stream-listener
You need to add the actuator Boot starter and inject the BindingsEndpoint
to stop/start the binding.
You can set autoStartup
to false to prevent the binding from starting immediately.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论