Home » Java » Spring Integration Error Channel for async operations configuration

Spring Integration Error Channel for async operations configuration

Posted by: admin October 22, 2018 Leave a comment

Questions:

I am trying to configure the a HttpRequestExecutingMessageHandler

    @Bean
public HttpRequestExecutingMessageHandler httpEnrollHandlerKairos() {  
    HttpRequestExecutingMessageHandler handler =  new HttpRequestExecutingMessageHandler(kairosProperties.getEnrollUrl()); 
    handler.setOutputChannel(channelConfiguration.kairosResponseChannel());
    handler.setExpectReply(true);
    handler.setMessageConverters(httpMessageConverters);
    handler.setHttpMethod(HttpMethod.POST);
    handler.setExpectedResponseType(EnrollResponse.class); 
    handler.setHeaderMapper(defaultHeaderMapper);
    return handler;
}

And with the following flow.

public IntegrationFlow kairosEnrollFlow() { 
        return IntegrationFlows
                .from(channelConfiguration.kairosEnrollChannel())
                .<Agreement , EnrollRequest>transform(p -> transformAgreementEnrollRequest(p))
                .transform(Transformers.toJson())
                .headerFilter(httpRequestHeaderFilters())
                .enrichHeaders(m -> m.header(APP_ID, kairosProperties.getAppId()))
                .enrichHeaders(m -> m.header(APP_KEY, kairosProperties.getAppKey()))
                .handle(httpEnrollHandlerKairos())
                .get();
    }

I put an enrichHeaders on this flow for the errorChannel with no results…

I configure an Autowired PS CHannel for the errorChannel as follows,

@Autowired
@Qualifier("errorChannel")
private PublishSubscribeChannel errorChannel;

My error handler flow… (redirect to another errorChannel for convenience purposes) my objective is to configure specific error channels for some sort of different problems on the application.

@Autowired
    @Qualifier("errorChannel")
    private PublishSubscribeChannel errorChannel;

    @Autowired
    private ChannelConfiguration channelConfiguration;

    @Bean
    public IntegrationFlow errorHandlerFlow() {
        return IntegrationFlows.from(errorChannel)
        .<Message<?> , Message<ErrorMessage>>transform(m -> handleExceptionMessage(m))
        .channel(channelConfiguration.errorHandlerOutputChannel())
        .get();
    }

    public Message<ErrorMessage> handleExceptionMessage(Message<?> message)
    {
        MessagingException me = (MessagingException) message.getPayload();
        MessageHeaders mh = me.getFailedMessage().getHeaders(); 
        return MessageBuilder.withPayload(new ErrorMessage()).copyHeaders(mh).build();
    }

But afterhundred of tries i couldn’t put this errorChannel to work, the application on the send method fires an exception, and the errorChannel and the “errorFlow” configured is never called.

I Noticed that the application Handler is using teh GenericMessagingTemplate that on it turns has the following code.

I tried to use the headers (Message and IntegrationUtils), and nothin ” TemporaryReplyChannel tempReplyChannel = new TemporaryReplyChannel(this.throwExceptionOnLateReply);
requestMessage = MessageBuilder.fromMessage(requestMessage).setReplyChannel(tempReplyChannel)
.setHeader(this.sendTimeoutHeader, null)
.setHeader(this.receiveTimeoutHeader, null)
.setErrorChannel(tempReplyChannel).build();”.

which does not let to override the errorChannel never…

Any tip how to do this.

Does anyone knows what happens, all channels on question are asynchronous.

Any help to clarify the configuration of the error channel will be glad.

Kind Regards,

José Carlos Canova.

Answers: