【问题标题】:Spring Cloud Stream - Consume Data on Demand manually?Spring Cloud Stream - 手动使用按需数据?
【发布时间】:2026-01-31 13:25:01
【问题描述】:

使用 Spring Data Stream,如何从队列开始读取并停止按需读取?

我想要这样的东西:

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

}

【问题讨论】:

    标签: spring-boot spring-integration spring-cloud-stream spring-amqp spring-rabbit


    【解决方案1】:

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

    查看我对this question的回复。

    【讨论】: