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


I am trying to configure the a HttpRequestExecutingMessageHandler

public HttpRequestExecutingMessageHandler httpEnrollHandlerKairos() {  
    HttpRequestExecutingMessageHandler handler =  new HttpRequestExecutingMessageHandler(kairosProperties.getEnrollUrl()); 
    return handler;

And with the following flow.

public IntegrationFlow kairosEnrollFlow() { 
        return IntegrationFlows
                .<Agreement , EnrollRequest>transform(p -> transformAgreementEnrollRequest(p))
                .enrichHeaders(m -> m.header(APP_ID, kairosProperties.getAppId()))
                .enrichHeaders(m -> m.header(APP_KEY, kairosProperties.getAppKey()))

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

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

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.

    private PublishSubscribeChannel errorChannel;

    private ChannelConfiguration channelConfiguration;

    public IntegrationFlow errorHandlerFlow() {
        return IntegrationFlows.from(errorChannel)
        .<Message<?> , Message<ErrorMessage>>transform(m -> handleExceptionMessage(m))

    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)

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.