如何让 Spring Cloud Stream 在应用程序没有生产者时创建 RabbitMQ 队列和绑定?

How to make Spring Cloud Stream create RabbitMQ queues and binding when the application has no producers?

我正在使用 Spring Boot 2.0.1 并且 Spring 云依赖项是从以下位置导入的:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Finchley.RC1</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

我认为感兴趣的依赖项是这些:

<dependencies>
    ...
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-reactive</artifactId>
    </dependency>
    ...
</dependencies>

在我的 application.yaml 中,我添加了多个消费者绑定:

spring:
  cloud:
    stream:
      bindings:
        input1:
          bindingRoutingKey: key1.#
          binder: rabbit
          group: group1
          destination: dest-group1
          transacted: true
        input2:
          bindingRoutingKey: key2.#
          binder: rabbit
          group: group2
          destination: dest-group2
          transacted: true

例如,我读过 应该向生产者添加 requiredGroups 以便自动创建队列和绑定。但是我的应用程序不产生任何消息,它只使用其他应用程序发布的消息,所以我没有定义任何生产者。我试图修改 application.yaml 文件以仅添加一个虚拟制作人:

spring:
  cloud:
    stream:
      bindings:
        dummyProducer:
          producer:
            requiredGroups: group1,group2
        input1:
          bindingRoutingKey: key1.#
          binder: rabbit
          group: group1
          destination: dest-group1
          transacted: true
        input2:
          bindingRoutingKey: key2.#
          binder: rabbit
          group: group2
          destination: dest-group2
          transacted: true

但这行不通。所以我的问题是:

我应该如何修改我的 application.yaml 文件(如果需要可能还有代码)以使 Spring 云流在启动时创建队列和绑定?

我们通常只在生产方提供交换;除非设置 required-groups,否则我们不会提供队列。

在消费者方面,我们总是提供队列(和交换)。

如果那没有发生,那就是其他地方出了问题;你有@EnableBinding吗?

显示您的应用程序代码。