multi output binding in spring cloud data flow

浪子不回头ぞ 提交于 2019-12-11 04:15:35

问题


I'm trying to setup a multi-destination bindings but for some reason, messages from the second channel are going to the first exchange.queue. For example:

spring:
  cloud:
     stream:
       bindings:
         output:
           destination: exchange1
           producer.requiredGroups: queue1
         output-other:
           destination: exchange2
           producer.requiredGroups: queue2

I also used org.springframework.cloud.stream.messaging.Source for the default Output and created a dedicated Source Binding for output-other channel

public interface OtherSource {

    String OUTPUT = "output-other";

    @Output(OtherSource.OUTPUT)
    MessageChannel output();
}

and the producer class

@EnableBinding(Source.class)
public class OutputSender { 
    private final Source source;

    public void send(Output1 obj) {
        Message message = toMessage(obj);
        this.source.output().send(message);
    }
 }

this works as expected. messages are sent to the correct queue (exchange1.queue1)

second producer:

 @EnableBinding(OtherSource.class)
 public class OutputOtherSender {
     OtherSource source;

     public void send(Output2 obj) {
         Message message = toMessage(obj)
         this.source.output().send(obj);
     }
 }

2 issues with this setup:

  1. exchange2.queue2 is not created (something wrong with application.yml configuration?)
  2. messages that are sent using OtherSource are going to exchange1.queue1

Dependencies

<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>

回答1:


By default, the stream applications in Spring Cloud Data Flow are linear, meaning the applications are bound to one another using single output->single input.

If you want to have your stream using multiple input/output destinations, then you have to manually configure your bindings(using the Spring Cloud Stream properties) and define your application as app type - a special type for a streaming app in SCDF that lets the user configure the bindings manually.

For more information on this, you can refer: https://dataflow.spring.io/docs/feature-guides/streams/stream-application-dsl/



来源:https://stackoverflow.com/questions/56854655/multi-output-binding-in-spring-cloud-data-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!