如何在Spring Boot应用中启动和停止Google Pub/Sub订阅者?

huangapple go评论160阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年10月27日 14:25:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/64549232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定