SimpleMessagingGateway - Error appears in sender channel.
Error appears in sender channel instead of provided Error Channel from behind the SimpleMessagingGateway.
--------------------------------------------
Hello everybody, I noticed an issue with message’s error channel header (MessageHeaders.ERROR_CHANNEL) passing through the SimpleMessagingGateway.
Perhaps I have;
1. Channel A sends a message with ERROR_CHANNEL as “MyErrorChannel” to Channel B
2. Channel B process message and if any errors (in my case Uncategorized JMS exception from Ibm MQ)
Channel B passes error to the “MyErrorChannel” as I expects.
So now, I need to set both ways timeouts between Channel A and Channel B. Ok, that’s good there is org.springframework.integration.gateway.SimpleMess agingGateway class – put it in-between, set timeouts and go…
Correct? Unfortunately, it’s quite not correct. :)
With it - Uncategorized JMS exception appears in channel A, not in the “MyErrorChannel”.
Why? Because of implementation of inner private static :eek: class TemporaryReplyChannel in the
org.springframework.integration.channel.MessageCha nnelTemplate.
so point is:
Code:
private Message<?> doSendAndReceive(Message<?> request, MessageChannel channel) {
Object originalReplyChannelHeader = request.getHeaders().getReplyChannel();
Object originalErrorChannelHeader = request.getHeaders().getErrorChannel();
TemporaryReplyChannel replyChannel = new TemporaryReplyChannel(this.receiveTimeout);
request = MessageBuilder.fromMessage(request)
.setReplyChannel(replyChannel)
.setErrorChannel(replyChannel) .build();
if (!this.doSend(request, channel)) {
throw new MessageDeliveryException(request, "failed to send message to channel");
}
Message<?> reply = this.doReceive(replyChannel);
if (reply != null) {
reply = MessageBuilder.fromMessage(reply)
.setHeader(MessageHeaders.REPLY_CHANNEL, originalReplyChannelHeader)
.setHeader(MessageHeaders.ERROR_CHANNEL, originalErrorChannelHeader)
.build();
}
return reply;
}
It changes original Error Channel header to the same replyChannel and of course Channel B passes my dumb Uncategorized JMS exception back to channel A and not to the “MyErrorChannel” as it was before.
Because of “inner private static” :rolleyes:, SimpleMessagingGateway, as well as MessageChannelTemplate becomes useless for my needs.