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

wbgh16ku  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(297)

如何设置多个输入通道输出到同一目的地
我有以下配置:

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()
  }

}
我想使用springcloudstream3.0函数绑定名。

beer -> notification
scotch -> notification

最好的方法是什么?

hgb9j2n6

hgb9j2n61#

我建议这样做(基于此):

@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

这样,两个输入 beer 和输入到 scotch 发送到 labron

相关问题