1

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.

J.K
  • 11
  • 3

1 Answers1

1

See this answer 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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179