【问题标题】:How to make Spring Cloud Stream create RabbitMQ queues and binding when the application has no producers?当应用程序没有生产者时,如何让 Spring Cloud Stream 创建 RabbitMQ 队列和绑定?
【发布时间】:2018-05-29 12:25:06
【问题描述】:

我正在使用 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

例如,我读过here,应该将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 Cloud 流在启动时创建队列和绑定?

【问题讨论】:

    标签: java spring spring-boot rabbitmq spring-cloud-stream


    【解决方案1】:

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

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

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

    显示您的应用程序代码。

    【讨论】:

    • 它确实有效,问题是当我在 src/main/resources 文件夹中的资源中声明 application.yaml 但 src/test/resources 文件夹为空时,我希望它能够工作.我认为当 src/test/resources 为空时,测试会从 src/main/resources 获取 application.yaml,但事实并非如此。
    猜你喜欢
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    相关资源
    最近更新 更多