【发布时间】:2019-07-02 14:24:07
【问题描述】:
我正在尝试设置多目标绑定,但由于某种原因,来自第二个频道的消息将发送到第一个exchange.queue。例如:
spring:
cloud:
stream:
bindings:
output:
destination: exchange1
producer.requiredGroups: queue1
output-other:
destination: exchange2
producer.requiredGroups: queue2
我还使用org.springframework.cloud.stream.messaging.Source 作为默认输出,并为output-other 通道创建了专用的源绑定
public interface OtherSource {
String OUTPUT = "output-other";
@Output(OtherSource.OUTPUT)
MessageChannel output();
}
和生产者类
@EnableBinding(Source.class)
public class OutputSender {
private final Source source;
public void send(Output1 obj) {
Message message = toMessage(obj);
this.source.output().send(message);
}
}
这按预期工作。消息被发送到正确的队列 (exchange1.queue1)
第二个制作人:
@EnableBinding(OtherSource.class)
public class OutputOtherSender {
OtherSource source;
public void send(Output2 obj) {
Message message = toMessage(obj)
this.source.output().send(obj);
}
}
2 此设置的问题:
-
exchange2.queue2未创建(application.yml 配置有问题?) - 使用
OtherSource发送的消息将发送到exchange1.queue1
依赖关系
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
【问题讨论】:
标签: spring spring-boot spring-cloud spring-cloud-dataflow