【问题标题】:multi output binding in spring cloud data flowSpring Cloud数据流中的多输出绑定
【发布时间】: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 此设置的问题

  1. exchange2.queue2 未创建(application.yml 配置有问题?)
  2. 使用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


    【解决方案1】:

    默认情况下,Spring Cloud Data Flow 中的流应用程序是线性的,这意味着应用程序使用单输出->单输入相互绑定。

    如果您想让您的流使用多个输入/输出目的地,那么您必须手动配置您的绑定(使用 Spring Cloud Stream 属性)并将您的应用程序定义为 app 类型 - 流应用程序的特殊类型在 SCDF 中,允许用户手动配置绑定。

    关于这方面的更多信息,您可以参考:https://dataflow.spring.io/docs/feature-guides/streams/stream-application-dsl/

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2019-07-23
      • 2019-03-02
      • 2018-11-27
      相关资源
      最近更新 更多