Spring Cloud Stream - 手动按需使用数据?

Spring Cloud Stream - Consume Data on Demand manually?

使用Spring数据流,如何从队列开始读取并按需停止读取?

我想要这样的东西:

@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?
  }

}

不能用静态方法完成;自动装配 BindingsEndpoint 并使用 changeState() 方法。

查看我对 的回答。