0

Using Spring Data Stream, How can I start reading from a queue and stop reading on demand?

I want to so something like this:

@EnableBinding(Sink.class)
public class SomeConsumer {

  @StreamListener(target = Sink.INPUT)
  public void receiveMsg(Message<String> message)
  {
    logger.info(" received new message [" + message.toString() + "] ");
  }

  public static void startReceiving()
  {
     //How to implement this logic?
  }

  public static void stopReceiving()
  {
     //How to implement this logic?
  }

}
Jerald Baker
  • 1,121
  • 1
  • 12
  • 48

1 Answers1

1

It can't be done in a static method; autowire the BindingsEndpoint and use the changeState() method.

See my answer to this question.

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