繁体   English   中英

带有Rabbit Binder的Spring Cloud Stream - 源/接收器队列名称不匹配

[英]Spring Cloud Stream with Rabbit Binder - source/sink queue names don't match

最近,我开始使用Spring Cloud Stream和RabbitMQ binder。

如果我理解正确的一切,当两个服务要通过的消息,应该发送邮件配置和其他应接收消息的接收器 -两者都应该使用相同的通道

我有名为testchannel 频道 但是我注意到,该创建了RabbitMQ绑定:

  • 交换testchannel
  • 路由密钥testchannel
  • queue testchannel.default (持久),

sink创建了RabbitMQ绑定:

  • 交换testchannel
  • 路由密钥#
  • queue testchannel.anonymous.RANDOM_ID (excusive)。

为简洁起见,我跳过了前缀。

现在我运行两个应用程序。 第一个向testchannel交换发送消息,然后路由到两个队列(我假设路由密钥是testchannel )。 第二个应用程序使用来自随机队列的消息,但永远不会消耗来自默认队列的消息。

我的另一个问题是 - 第二个应用程序只使用接收 ,但它也为输出通道创建绑定,默认output ,因为我没有指定任何东西。

我使用相同的Gradle脚本构建两个应用程序:

buildscript {
    ext {
        springBootVersion = '1.3.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/snapshot' }
    maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
    compile(
            'org.springframework.cloud:spring-cloud-starter-stream-rabbit',
    )
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.BUILD-SNAPSHOT"
    }
}

第一个应用属性:

server.port=8010
spring.cloud.stream.binder.rabbit.default.prefix=z.
spring.cloud.stream.bindings.input=start
spring.cloud.stream.bindings.output=testchannel
spring.rabbitmq.addresses=host1:5672,host2:5672
spring.rabbitmq.username=user
spring.rabbitmq.password=psw

Fisrt应用程序源代码:

@EnableBinding(Processor.class)
...
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public byte[] handleIncomingMessage(byte[] payload) {}

第二个应用属性:

server.port=8011
spring.cloud.stream.binder.rabbit.default.prefix=z.
spring.cloud.stream.bindings.input=testchannel
spring.rabbitmq.addresses=host1:5672,host2:5672
spring.rabbitmq.username=user
spring.rabbitmq.password=psw

第二个应用源代码:

@EnableBinding(Sink.class)
...
@ServiceActivator(inputChannel = Sink.INPUT)
public void handleIncomingMessage(byte[] payload) {}

所以我的问题是。

  • 不应使用相同的通道,结果是同一个代理队列? 实现这一目标的适当配置是什么? (我的目标是拥有多个接收服务实例,但只有一个应该使用该消息。)
  • 当我只使用接收时框架是否应该创建输出绑定? 如果是,如何禁用它。

默认; 消费者各自得到自己的队列; 这是一个发布/订阅方案。

有一个消费者group的概念,因此您可以让多个实例竞争来自同一队列的消息。

绑定生成器时,绑定默认队列。

如果您想订阅default组; 你必须设置组:

spring.cloud.stream.bindings.input.group=default

如果您未提供组,则会获得独占的自动删除队列。

编辑

由于默认队列是持久的,您还应该设置

spring.cloud.stream.bindings.input.durableSubscription=true

消费者绑定时避免警告,如果消费者先绑定并且队列尚不存在,则确保队列是持久的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM