Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Spring Integration TCP adapters

  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,147

    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,147

    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,147

    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

  7. #7
    Join Date
    May 2005
    Posts
    28

    Default

    Thanks Gary. Appreciate your help.

  8. #8
    Join Date
    May 2005
    Posts
    28

    Default

    Why do I get these annoying errors in the application-context.xml?

    cvc-complex-type.3.2.2: Attribute 'error-channel' is not allowed
    to appear in element 'int:gateway'.

    The prefix "int-ip" for element "int-ip:tcp-connection-factory" is
    not bound.

    My config is
    Code:
    <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"
    error-channel="errorChannel"/> 
    
    <int:channel errorChannel />
    
    <int:transformer ref="someBeanToTransformExceptionToXML"
        input-channel="errorChannel" output-channel="toTCP" />
    
    <int:channel id="toTCP" />
    
    <int-ip:tcp-connection-factory id="client"
        	type="client"
        	host="localhost"
        	port="#{server.port}"
        	single-use="true"
       	 	so-timeout="10000"
        	deserializer="javaDeserializer"
        	serializer="javaSerializer"/>
    
    <int-ip:tcp-outbound-channel-adapter input-channel="toTCP" connectionFactory= ... />
    Last edited by Invincible; Oct 25th, 2011 at 03:57 PM.

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

    Default

    What versions of STS, SI are you using?

    STS might be using an old cached version of the schema. Try clearing the cache in Window | Preferences | General | Network Connections | Cache, and then cleaning all projects.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  10. #10
    Join Date
    May 2005
    Posts
    28

    Default

    STS 2.6
    SI 2.0

    I cleared the cache, Cleaned the projects, build them all. I still get the error
    "The prefix "int-ip" for element "int-ip:tcp-connection-factory" is
    not bound." at this configuration
    Code:
    <int:channel id="toTCP" />
    
    <int-ip:tcp-connection-factory id="client"
        	type="client"
        	host="localhost"
        	port="#{server.port}"
        	single-use="true"
       	 	so-timeout="10000"
        	deserializer="javaDeserializer"
        	serializer="javaSerializer"/>

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
  •