Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration TCP adapters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          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" />

          Comment


          • #6
            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.

            Comment


            • #7
              Thanks Gary. Appreciate your help.

              Comment


              • #8
                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, 04:57 PM.

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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"/>

                    Comment


                    • #11
                      Did you add the namespace to the file? Namespaces tab at the bottom of the editor.

                      Can you provide your entire XML preamble (from <?xml... down to your first element?

                      Comment


                      • #12
                        Code:
                        <?xml version="1.0" encoding="UTF-8"?>
                        <beans xmlns="http://www.springframework.org/schema/beans"
                        	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        	xmlns:mvc="http://www.springframework.org/schema/mvc"
                        	xmlns:context="http://www.springframework.org/schema/context"
                        	xmlns:int="http://www.springframework.org/schema/integration"
                        	xmlns:task="http://www.springframework.org/schema/task"
                        	xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
                        	xsi:schemaLocation="
                        		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        		http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
                        		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
                        		http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">
                        		
                        	<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>
                        
                        	<bean id="dlService" scope="prototype" class="com.fgv.sm.dldr.NonSavingDLSImpl">
                        		<constructor-arg name="chunkSize" value="30" />
                        		<constructor-arg name="connectionTimeout" value="10000" />
                        		<constructor-arg name="readTimeout" value="10000" />
                        	</bean>
                        	
                        	<int:service-activator input-channel="inputChannel"
                            	output-channel="outputChannel"
                                ref="dlService"
                                method="download">
                            	<!-- <int:poller task-executor="executor">
                        			<int:interval-trigger interval="100"/>
                        		</int:poller> -->
                            </int:service-activator>
                            
                            <int:channel id="dlErrorChannel"/>
                            
                            <int:gateway id="dlServiceGateway" 
                        	     service-interface="com.fgv.sm.dldr.dlServiceGateway"
                        	     default-request-channel="inputChannel"
                                 default-reply-channel="doutputChannel" 
                                 error-channel="dlErrorChannel"/> 	
                        
                        	<int:transformer ref="someBeanToTransformExceptionToXML"
                            	input-channel="dlErrorChannel" 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-connection-factory id="server"
                            type="server"
                            port="1234"
                            deserializer="javaDeserializer"
                            serializer="javaSerializer"
                            using-nio="true"
                            single-use="true"/>
                            
                        	<int:channel id="replies">
                            <int:queue/>
                          </int:channel>
                        
                          <int-ip:tcp-outbound-channel-adapter id="outboundClient"
                            input-channel="toTCP" 
                            connection-factory="client"/>
                        
                          <int-ip:tcp-inbound-channel-adapter id="inboundClient"
                            channel="replies"
                            connection-factory="client"/>
                        
                          <int-ip:tcp-inbound-channel-adapter id="inboundServer"
                            channel="loop"
                            connection-factory="server"/>
                        
                          <int-ip:tcp-outbound-channel-adapter id="outboundServer"
                            channel="loop"
                            connection-factory="server"/>
                        
                          <int:channel id="loop"/>         
                                 
                                 
                            <ehcache:annotation-driven cache-manager="ehCacheManager" />
                        	
                        	<bean id="ehCacheManager"
                        		class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
                        		<property name="configLocation">
                        			<value>classpath:META-INF/config/ehcache.xml</value>
                        		</property>
                        	</bean>
                        	
                        </beans>

                        Comment


                        • #13
                          You need to add the int-ip namespace. Click the Namspaces tab at the bottom of the editor and check the int-ip box.

                          Comment

                          Working...
                          X