我正在将应用程序迁移到基于新函数的 Spring Cloud Stream 编程模型,但在事件路由上受阻。
我必须路由来自两个不同 kafka 主题的事件,我不知道如何将 functionRouter-in-0 绑定到两个不同的目的地。
通过向生产者端的每条消息添加一个 spring.cloud.function.definition
标头来完成路由。
假设我有
如何在配置中表达 RoutingFunction.FUNCTION_NAME 应该监听 topic1 AND topic2 ?
spring:
cloud:
function.definition: consumerA;consumerB;consumerC;consumerD
stream:
function.routing.enabled: true
bindings:
functionRouter-in-0:
destination: topic1
group: myService
consumer:
concurrency: 1
partitioned: false
maxAttempts: 1
functionRouter-in-0: # <== this oviously does not work because it's already defined above
destination: topic2
group: myService
consumer:
concurrency: 3
maxAttempts: 1
注意:我使用的是 3.0.11.RELEASE 版本
答案 0 :(得分:2)
关于绑定,基于注解的模型没有任何变化,正如它所解释的那样 here - "如果绑定代表一个消费者绑定(输入),它可以绑定到多个目的地,并且目标名称可以指定为逗号分隔的字符串值。" 所以。 . .
. . .
functionRouter-in-0:
destination: topic1, topic2
group: myService
. . .
我认为其余的内容是 here,它讨论了 ROUTING TO 和 FROM 以及您可以使用的不同机制 - 例如应用程序属性、消息头等。
此外,对于出站,您还有多种选择。 一种是 StreamBridge 和 ...sendto... 标头。
随时跟进。