I'm trying to wrap my head around the new functional binders in Spring Cloud Stream 3.x/
In the legacy style, I have a @StreamListener that receives a Message, then may produce 0..n messages on its output:
@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
}
In the new functional style, instead of a listener, I would define a bean like so:
@Bean
public Function<Payload, Result> processPayload() {
return value -> {
System.out.println("Received: " + payload);
// do stuff
return result; // (only one?)
};
}
Result
in response to a single received Payload
? (This is a splitter!)@Valid
to trigger bean validation with the legacy setup. Is there similar shorthand in functional land, or do I get to instantiate my own Validator
?Use Consumer<Payload>
instead of Function
together with a StreamBridge
.