Results 1 to 3 of 3

Thread: SimpleMessagingGateway - Error appears in sender channel.

  1. #1
    Join Date
    Dec 2010
    Posts
    2

    Default 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

    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” , SimpleMessagingGateway, as well as MessageChannelTemplate becomes useless for my needs.

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    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 http://static.springsource.org/sprin...ce/htmlsingle/). 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. #3
    Join Date
    Dec 2010
    Posts
    2

    Default

    Quote 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 at 08:26 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •