spring函数绑定将多个输入命名为spring cloud中的一个输出

spring函数绑定将多个输入命名为spring cloud中的一个输出,spring,spring-cloud-stream,Spring,Spring Cloud Stream,如何将多个输入通道设置为输出到同一目的地 我有以下配置: spring: cloud: stream: function: definition: beer;scotch bindings: notification: destination: labron beer-in-0: destination: wheat scotch-in-0:

如何将多个输入通道设置为输出到同一目的地

我有以下配置:

spring:
  cloud:
    stream:
      function:
        definition: beer;scotch
      bindings:
        notification:
          destination: labron
        beer-in-0:
          destination: wheat
        scotch-in-0:
          destination: wiskey
我想创建函数绑定,以便每个输入通道将其消息输出到通知绑定

因此,在相应的代码中:

@Service
class Notifications {
  @Bean
  fun beer(): Function<String, String> = Function {
    // wanted oout channel
    // beer -> notification
    it.toUpperCase()
  }

  @Bean
  fun scotch(): Function<String, String> = Function {
    // wanted oout channel
    // scotch -> notification
    it.toUpperCase()
  }

激活它的最佳方式是什么?

我建议使用类似的方式(基于):


这样,
啤酒
的输入和
苏格兰威士忌
的输入都被发送到
labron

+1到@orirab。只是想补充一些东西。如果你不想采取被动的方法,你仍然可以使用你原来的设置。您只需通过
…function.bindings…
属性将函数的输出绑定映射到同一目标。例如,
spring.cloud.stream.function.bindings.scotch-out-0=notification
spring.cloud.stream.function.bindings.beer-out-0=notification
。更多关于这个的信息
beer -> notification
scotch -> notification
    @Bean
    public Function<Tuple2<Flux<String>, Flux<String>>, Flux<String>> beerAndScotch() {
        return tuple -> {
            Flux<String> beerStream = tuple.getT1().map(item -> item.toUpperCase());
            Flux<String> scotchStream = tuple.getT2().map(item -> item.toUpperCase());
            return Flux.merge(beerStream, scotchStream);
        };
    }
spring:
  cloud:
    stream:
      function:
        definition: beerAndScotch
      bindings:
        notification:
          destination: labron
        beerAndScotch-in-0:
          // ...
        beerAndScotch-in-1:
          // ...
        beerAndScotch-out-0:
          destination: labron