如何使用 Spring Cloud Stream 3.x 的新功能绑定样式设置拆分器?
How to set up a splitter using Spring Cloud Stream 3.x's new functional binding style?
我正在努力研究 Spring Cloud Stream 3.x/
中的新功能活页夹
在传统风格中,我有一个接收消息的@StreamListener,然后可能会在其输出上产生 0..n 条消息:
@StreamListener(Channels.INPUT)
public void handle(@Valid @Payload Payload payload) {
// do stuff, then send multiple messages to the output channel:
channels.output().send(result); // Do this 0..n times
}
在新的函数式风格中,我会像这样定义一个 bean,而不是一个监听器:
@Bean
public Function<Payload, Result> processPayload() {
return value -> {
System.out.println("Received: " + payload);
// do stuff
return result; // (only one?)
};
}
- 如果我想 return 0..n
Result
响应接收到的单个 Payload
,我应该如何定义一个 Function bean? (这是分离器!)
- 我能够使用
@Valid
通过遗留设置触发 bean 验证。在功能区是否有类似的 shorthand,或者我是否可以实例化我自己的 Validator
?
使用 Consumer<Payload>
而不是 Function
和 StreamBridge
。
我正在努力研究 Spring Cloud Stream 3.x/
中的新功能活页夹在传统风格中,我有一个接收消息的@StreamListener,然后可能会在其输出上产生 0..n 条消息:
@StreamListener(Channels.INPUT)
public void handle(@Valid @Payload Payload payload) {
// do stuff, then send multiple messages to the output channel:
channels.output().send(result); // Do this 0..n times
}
在新的函数式风格中,我会像这样定义一个 bean,而不是一个监听器:
@Bean
public Function<Payload, Result> processPayload() {
return value -> {
System.out.println("Received: " + payload);
// do stuff
return result; // (only one?)
};
}
- 如果我想 return 0..n
Result
响应接收到的单个Payload
,我应该如何定义一个 Function bean? (这是分离器!) - 我能够使用
@Valid
通过遗留设置触发 bean 验证。在功能区是否有类似的 shorthand,或者我是否可以实例化我自己的Validator
?
使用 Consumer<Payload>
而不是 Function
和 StreamBridge
。