I tried to create a message filter via lambda expression to filter messages on a base of header value evaluation
IntegrationFlows.from(inputChannel())
.filter((Message<?> m) -> { return m.getHeaders().get(...)...; })
.transform(...)
.channel(outputChannel())
.get();
but got exception
Caused by: java.lang.ClassCastException: com.<...skipped...>.BusinessPayloadData cannot be cast to org.springframework.messaging.Message
Only this definition works for me
IntegrationFlows.from(inputChannel())
.filter(new MessageSelector(){
@Override
public boolean accept(Message<?>message){
return ...;
}
})
.transform(...)
.channel(outputChannel())
.get();
Is it possible to create MessageSelector
instance via lambda expression?
Like this:
.filter(Message.class, m -> m.getHeaders().get(...)...)
There is one more overloaded method to infer the object type for the target method invocation.
See LambdaMessageProcessor
source code. Since we can't infer the argument type from the Lambda directly Java: get actual type of generic method with lambda parameter, we have to do that like with one more top level type parameter.
Otherwise it ends up only like Object
, which the target method invocation treats like a type for the payload
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With