Error message handler is a one way and cannot configure output channel

33 Views Asked by At

I have the following configuration, and I used the following style used in Spring integration Java DSL service actuator (.handle) should use bean

    
@Bean
public IntegrationFlow flow(PollerMetada poller, FileReadingMessageSource source){
   return IntegrationFlows.from(source, e->e.poller(poller)
            .handle(this::mainHandle)
            .channel("somechannel")
            .get();
}

public FileRequest mainHandle(Message<?> message){
       ...
       return request;
    }

But I got error my handler is a one-way MessageHandler, how to make it not a one way so I can configure the output channel? Thank you

1

There are 1 best solutions below

0
Artem Bilan On BEST ANSWER

You use .handle(this::mainHandle) API. This one fully fits into a MessageHandler contract: void handleMessage(Message<?> message). Where your method is like this mainHandle(Message<?> message). So, the return type of your method is ignored because that method reference mapped to the MessageHandler knows nothing about return type - just void.

To make it working with the return type you need to use different API:

public <P> B handle(GenericHandler<P> handler) {

where contract is this:

Object handle(P payload, MessageHeaders headers);

To match it into your mainHandle() contract it has to be used like this:

.handle(Message.class, (p, h) -> mainHandle(p))

Or you can use method name-based API:

.handle(this, "mainHandle")