Results 1 to 7 of 7

Thread: How does error channel work in TCP adapters?

  1. #1
    Join Date
    May 2005
    Posts
    28

    Default How does error channel work in TCP adapters?

    Hi,

    I am trying to understand how the wiring works.

    my code is as under.
    Code:
    <int:gateway id="downloadServiceGateway"
    service-interface="com.directv.strammonitor.downloader.DownloadServiceGateway"
        	default-request-channel="downloadInputChannel"
        	default-reply-channel="downloadOutputChannel" 
    	error-channel="downloadErrorChannel"/> 
    
    	<int:channel downloadErrorChannel />
    
    	<int:transformer ref="downloadErrorToTransformExceptionToXML"
    input-channel="downloadErrorChannel" output-channel="errorTCPChannel" />
    How will Spring know that it has to now put the message to errorChannel? If the exception is thrown in the bean defined in inputchannel, is it then that the error message is sent to error channel?

    In my scenario, when a certain action fails, I need to capture the error message, add certain additional text and send an xml over TCP. I have an XML format defined. I also need to send another XML to let the receiver know that the system is alive every few seconds. How can I achieve this?

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,153

    Default

    If downloadInputChannel is a direct channel, and all downstream channels from there are direct channels then, yes, any downstream exception will be caught by the gateway and an ErrorMessage will be put on the error-channel.

    The payload of the ErrorMessage is a MessagingException which has two properties:

    * failedMessage - the message that failed
    * cause - the original exception


    To send keepalives use something like

    Code:
    <int:inbound-channel-adapter id="heartbeat" expression="'<ok/>'" channel="toReceiver" >
      <int:poller fixed-delay="5000" />
    </int:inbound-channel-adapter>
    Notice the single quotes around the literal SpEL expression.

    You can, of course, reference a bean and method to get the content, instead of using an expression.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    May 2005
    Posts
    28

    Default

    Thanks Gary. That was quick and a great help. Appreciate it.

    So, if I have a schema defined for the error XML and the heartbeat XML, can I use the bean to manipulate the message object to add nodes as in the schema that has been defined?

    For eg,

    Code:
    <int:transformer ref="downloadErrorToTransformExceptionToXML"
    input-channel="downloadErrorChannel" output-channel="errorTCPChannel" />
    can the downloadErrorToTransfornExceptionToXML bean have a method that gets the ErrorMessage object, updates it with the nodes that are defined in the schema and then it is put on the error channel?

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,153

    Default

    You can do whatever you want in a transformer. It doesn't "manipulate" the message; messages are immutable.

    A transformer gets an input message (preferably just its payload) and returns some other message.

    Something like this...

    Code:
    public String errorToXML(MessagingException e) {
    
        Object payload = e.getFailedMessage().getPayload();
        Exception actualException = e.getCause();
    
    ...
    
        return someString;
    }
    The new message out of the transformer will have someString as its payload.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    May 2005
    Posts
    28

    Default

    Thanks Gary. Appreciate your help.

  6. #6
    Join Date
    May 2005
    Posts
    28

    Default

    So, is this logging through error channel is asynchronous? I mean when the downloadInputChannel has certain operations to perform, and when errors are encountered, are those errors put on error channel and the error channel processing them happen asynchronously? Can my input channel continue with its own operations while error channel is processing the errors?

  7. #7
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,153

    Default

    No; it's synchronous; the exception handling is on the caller's thread by default.

    To hand off the error handling to another thread, just make the error channel a queue channel and add a poller.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

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
  •