Results 1 to 10 of 13

Thread: Spring Integration TCP adapters

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    28

    Default Spring Integration TCP adapters

    Hi,

    My requirement is to send a XML over TCP to a non spring component. I need to send messages very often. I was looking into Spring Integration TCP adapters and gateways as a solution. Is it mandatory to receive a response when a message is posted? In my scenario, I never get a response back.

    Thanks,
    Jan.

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

    Default

    No; an outbound channel adapter is "one way".

    If you do, occasionally, get a response you can add an inbound channel adapter (using the same connection factory).

    Gateways are request/reply based.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    May 2005
    Posts
    28

    Default

    Thanks Gary.

    So, I am already using input-output channels in my application. Basically, I do some process and I sent out the result to an output channel. If there were any errors, I need to capture that and send it as an xml to a different application through TCP. Can I configure a TCP outbound channel adapter as a error channel?

    Thanks,
    Jan.

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

    Default

    Can you post your configuration? What is the entry point to your flow? Normally, for error handling, you declare an error-channel on the endpoint that starts your flow. If an error occurs upstream (and you use direct channels all the way), the exception is caught in the inbound endpoint and an ErrrorMessage is sent to the error-channel.

    The ErrorMessage has a payload of type MessagingException, which has two properties

    * cause - the original exception
    * failedMessage - the message that was being processed when the exception occurred.

    You can do whatever you want on the error channel, including adding a transformer to create the XML format you want, and sending it over TCP.

    Hope that helps.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    May 2005
    Posts
    28

    Default

    My configuration is something like this:

    <int:channel id="inputChannel">
    <int:dispatcher task-executor="executor" />
    </int:channel>

    <task:executor id="executor"
    pool-size="30"
    queue-capacity="10000"
    rejection-policy="CALLER_RUNS" />

    <int:channel id="outputChannel">
    <int:queue/>
    </int:channel>

    <int:service-activator input-channel="inputChannel"
    output-channel="outputChannel"
    ref="doSomeService"
    method="service">
    </int:service-activator>

    <int:gateway id="serviceGateway"
    service-interface="serviceGateway"
    default-request-channel="inputChannel"
    default-reply-channel="outputChannel" />

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

    Default

    Please use [ code ] ... [ /code ] tags (no spaces inside brackets) around code and config; it makes it easier to read.

    So, just add an error channel to your gateway...

    Code:
    <int:gateway id="serviceGateway"
        service-interface="serviceGateway"
        default-request-channel="inputChannel"
        default-reply-channel="outputChannel" 
        error-channel="errorChannel"/> 
    
    <int:channel errorChannel />
    
    <int:transformer ref="someBeanToTransformExceptionToXML"
        input-channel="errorChannel" output-channel="toTCP" />
    
    <int:channel id="toTCP" />
    
    <int-ip:tcp-outbound-channel-adapter input-channel="toTCP" connectionFactory= ... />
    Unless you have specific reasons for the explicit <dispatcher/> and <queue/> elements, I would suggest you remove them.

    That way everything happens on the caller's thread and, if there is an exception sending to TCP, that exception will be thrown to the caller.
    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
  •