Announcement Announcement Module
No announcement yet.
SimpleMessagingGateway - Error appears in sender channel. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 class TemporaryReplyChannel in the nnelTemplate.
    so point is:
    	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)
    				.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)
    		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” , SimpleMessagingGateway, as well as MessageChannelTemplate becomes useless for my needs.

  • #2
    That is correct. The error message will only be generated and sent to the error-channel if the flow is asynchronous. However, this behavior was also slightly changed for Gateways in Spring Integration 2.0 (see section 7.2 Since Gateways are unique in the fact that they are both Producers and Consumers, specifying error-channel on the gateway would essentially allow you to intercept and exception and do something to it if you wish, otherwise it will be re-thrown back to the caller as Messaging Exception.
    Also, I see that you are not using Spring Integration 2.0. I see it from the fact that you are referring to SimpleMessagingGateway which was removed in 2.0. Is there a reason why you are not upgrading?


    • #3
      Originally posted by oleg.zhurakousky View Post
      Also, I see that you are not using Spring Integration 2.0. I see it from the fact that you are referring to SimpleMessagingGateway which was removed in 2.0. Is there a reason why you are not upgrading?
      Thanks for reply, Oleg.

      Yes, downbelow I have asynchronous channels and they have to report to Error Channel, not to the caller.

      yes there is reason, and it is not Spring Integration fault
      It is quite long process to apply new versions in large organization and large project. We have bunch of policies around, have to get new version as "Approved Technology" first, have a budget, resources to test existing systems ... and so on. Of course project is going and requirements cannot wait.

      Regarding problem, as I understood given code is not about error channel defined for gateway it-self - MessageChannelTemplate explicity modifies message to report errors to the calling channel instead of channel message suppose to. Even when gateway has an error channel it replaces anyway. Behind Template all downstream channels do not know about original Error Channel message had before Template.
      Whatever I do not use SimpleMessagingGateway anymore.
      Last edited by vadim_begun; Dec 10th, 2010, 08:26 AM.