Spring Cloud Stream 不创建队列

Spring Cloud Stream does not create a queue

我正在尝试使用 RabbitMQ 配置一个简单的 Spring Cloud Stream 应用程序。我使用的代码大部分取自spring-cloud-stream-samples。 我有一个入口点:

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

以及示例中的简单消息生成器:

@EnableBinding(Source.class)
public class SourceModuleDefinition {

    private String format = "yyyy-MM-dd HH:mm:ss";

    @Bean
    @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "${fixedDelay}", maxMessagesPerPoll = "1"))
    public MessageSource<String> timerMessageSource() {
        return () -> new GenericMessage<>(new SimpleDateFormat(this.format).format(new Date()));
    }

}

此外,这里是application.yml配置:

fixedDelay: 5000
spring:
  cloud:
    stream:
      bindings:
        output:
          destination: test

当我 运行 这个例子时,它连接到 Rabbit 并创建一个名为 test 的交换。但我的问题是,它不会自动创建队列和绑定。我可以看到 Rabbit 中的流量,但我所有的消息都消失了。虽然我需要他们留在某个队列中,除非他们被消费者阅读。

也许我误解了什么,但从我阅读的所有主题来看,似乎 Spring Cloud Stream 应该自动创建一个队列和一个绑定。如果没有,我如何配置它以便保留我的消息?

我正在使用 Spring Cloud Brixton.SR5 和 Spring Boot 1.4.0.RELEASE.

一旦您启动消费者应用程序,就会创建一个队列。

在 Rabbit MQ 的情况下,我们为每个消费者组都有单独的队列并且我们无法事先知道所有组,如果您想为预先知道的消费者组自动创建队列,您可以使用生产者的 requiredGroups 属性。这将确保消息一直存在,直到该组的消费者启动。

查看详情:http://docs.spring.io/spring-cloud-stream/docs/Brooklyn.BUILD-SNAPSHOT/reference/htmlsingle/#_producer_properties

您需要一个消费者才能创建队列。

在这里您可以找到使用 rabbitMq 的生产者和消费者的示例:

http://ignaciosuay.com/how-to-implement-asyncronous-communication-between-microservices-using-spring-cloud-stream/