最近,我開始玩Spring Cloud Stream和RabbitMQ活頁夾。春季雲流與兔活頁夾 - 源/匯隊列名稱不匹配
如果我正確理解的一切,當兩個服務想傳遞消息,一個應該配置源用於發送消息和其他應配置水槽用於接收消息 - 兩者都應該使用相同的信道。
我有頻道取名爲testchannel
。我注意到,雖然,源創建RabbitMQ的結合:
- 交換
testchannel
, - 路由關鍵
testchannel
, - 隊列
testchannel.default
(耐久),
而沉創建的RabbitMQ綁定:
- 交換
testchannel
, - 路由密鑰
#
, - 隊列
testchannel.anonymous.RANDOM_ID
(excusive)。
爲了簡潔起見,我跳過了前綴。
現在,當我運行這兩個應用程序。第一個發送消息到testchannel
交換,然後路由到這兩個隊列(我假設路由密鑰是testchannel
)。第二個應用程序使用來自隨機隊列的消息,但來自默認隊列的消息永遠不會消耗。
我的另一個問題是 - 2應用程序只使用沉,但它也創造了輸出渠道,這是output
默認綁定,因爲我還沒有任何規定。
我建立具有相同搖籃腳本這兩個應用:
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
最前一頁應用程序的源代碼:
@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) {}
所以我的問題是。
- 不應源和水槽使用相同的信道和作爲導致相同的代理隊列?什麼是適當的配置來實現這一目標? (我的目標是有多個接收器服務實例,但只有一個應該消費該消息。)
- 框架創建輸出綁定當我只使用水槽?如果是的話,如何禁用它。
你說默認。是否有任何配置可以讓我將其更改爲對等方案?直接渠道似乎更適合我的需求。 – waste
將組設置爲'default'即可。 –
我沒有更改第一項服務(A)。我將第二個服務的(B)輸入頻道組更改爲'default'。當我運行A時,B - B抱怨隊列的耐久性。例外:'頻道錯誤;協議方法:#method(reply-code = 406,reply-text = PRECONDITION_FAILED - 隊列'z.test.default'在vhost'/'中不等同的arg'持久':收到'false',但是current是'true',class-id = 50,method-id = 10)' –
waste