Announcement Announcement Module
Collapse
No announcement yet.
tcp-outbound-gateway - failed to send Message to channel Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • tcp-outbound-gateway - failed to send Message to channel

    Hello,

    I am trying to follow the tcp sample off GitHub (http://git.springsource.org/spring-i...ver/readme.txt) and I am getting an error when trying to send a message to a tcp server. The error I get is "failed to send Message to channel." Below is my xml configuration. What am I doing wrong :-(. I am using Spring Integration 2.0.1 RELEASE.

    Code:
    <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
    			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    			 xmlns="http://www.springframework.org/schema/integration"
    			 xmlns:context="http://www.springframework.org/schema/context"
    			 xmlns:jms="http://www.springframework.org/schema/integration/jms"
    			 xmlns:ip="http://www.springframework.org/schema/integration/ip"			 
    			 xmlns:tx="http://www.springframework.org/schema/tx"
    			 xsi:schemaLocation="http://www.springframework.org/schema/beans
    								 http://www.springframework.org/schem...-beans-3.0.xsd
    								 http://www.springframework.org/schema/context
    								 http://www.springframework.org/schem...ontext-3.0.xsd
    								 http://www.springframework.org/schema/integration
    								 http://www.springframework.org/schem...ntegration.xsd
    								 http://www.springframework.org/schema/integration/jms
    								 http://www.springframework.org/schem...ration-jms.xsd
    								 http://www.springframework.org/schema/integration/ip
    								 http://www.springframework.org/schem...gration-ip.xsd
    								 http://www.springframework.org/schema/tx
    								 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">		
    
    	<beans:bean id="appContext" class="com.company.transport.util.AppContext" />
    	
    	<ip:tcp-connection-factory id="clientTcpConnectionFactory" type="client" host="localhost" port="59260" using-nio="true" so-timeout="10000" />
    	<gateway id="gw" service-interface="com.company.transport.client.monitor.TransportClientMonitorGateway" default-request-channel="outgoingTcpMonitorChannel"/>
    	<channel id="outgoingTcpMonitorChannel" />
    	
    	<ip:tcp-outbound-channel-adapter channel="outgoingTcpMonitorChannel" connection-factory="clientTcpConnectionFactory" />
    	
    	<ip:tcp-connection-factory id="crLfServer"
    		type="server"
    		port="59260"/>
    			
    	<ip:tcp-inbound-channel-adapter
    		connection-factory="crLfServer"
    		channel="serverBytes2StringChannel"/>
    	
    	<channel id="toSA" />
    	
    	<transformer id="serverBytes2String"
    		input-channel="serverBytes2StringChannel"
    		output-channel="toSA" 
    		expression="new String(payload)"/>	
    	
    	<beans:bean id="transportClientMonitor" class="com.company.transport.client.monitor.TransportClientMonitor" init-method="run" />
    	
    </beans:beans>
    Last edited by thehin; Jan 11th, 2011, 02:30 PM.

  • #2
    I see that you are connecting gateway to an adapter.
    Gateways are by-directional while adapters are uni-directional so there will be no reply for he gateway. That is just from the first look.

    Also, could you please explain your use case?

    Comment


    • #3
      The channel 'toSA' has no subscriber. You need to consume messages sent to it by the inbound-channel-adapter.

      Comment


      • #4
        OK. So I scoured around the web for some more examples. I happened to stumble upon a post on this forum. I tried copying it and created the Gateway and Service in code but I get a new error: failure occurred in gateway sendAndReceive, failed to send Message to channel 'input'. Below is my new configuration.

        Code:
        <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
        			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        			 xmlns="http://www.springframework.org/schema/integration"
        			 xmlns:context="http://www.springframework.org/schema/context"
        			 xmlns:jms="http://www.springframework.org/schema/integration/jms"
        			 xmlns:ip="http://www.springframework.org/schema/integration/ip"			 
        			 xmlns:tx="http://www.springframework.org/schema/tx"
        			 xsi:schemaLocation="http://www.springframework.org/schema/beans
        								 http://www.springframework.org/schem...-beans-3.0.xsd
        								 http://www.springframework.org/schema/context
        								 http://www.springframework.org/schem...ontext-3.0.xsd
        								 http://www.springframework.org/schema/integration
        								 http://www.springframework.org/schem...ntegration.xsd
        								 http://www.springframework.org/schema/integration/jms
        								 http://www.springframework.org/schem...ration-jms.xsd
        								 http://www.springframework.org/schema/integration/ip
        								 http://www.springframework.org/schem...gration-ip.xsd
        								 http://www.springframework.org/schema/tx
        								 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">		
        
        	<beans:bean id="appContext" class="com.company.transport.util.AppContext" />
        	
        	<gateway id="gw" 
        	             service-interface="com.company.transport.client.monitor.TransportClientMonitorGateway"
        	             default-request-channel="input"
        	             default-reply-channel="replies"/>
        
        	<ip:tcp-connection-factory id="client"
        		type="client"
        		host="localhost"
        		port="4700"
        		single-use="true"
        		so-timeout="10000"
                        using-nio="true"
                />
        	
        	<channel id="input" />	
        	<channel id="replies" />
        	
        	<ip:tcp-outbound-gateway id="outGateway"
        		request-channel="input"
        		reply-channel="replies"
        		connection-factory="client"
        		request-timeout="10000"
        		reply-timeout="10000"
        		/>
        		
        	<!-- Server side -->
        	
        	<ip:tcp-connection-factory id="crLfServer"
        		type="server"
        		port="4700"/>
        			
        	<ip:tcp-inbound-gateway id="gatewayCrLf"
        		connection-factory="crLfServer"
        		request-channel="toSA" />
        		
        	<channel id="toSA" />
        
        	<service-activator id="SA" 
        		input-channel="toSA"
        		ref="echoService"
        		method="test"
        	/>
        
        	<beans:bean id="echoService" class="com.company.transport.client.monitor.EchoService" />
        	
        	
        	<beans:bean id="transportClientMonitor" class="com.company.transport.client.monitor.TransportClientMonitor" init-method="run" />
        	
        </beans:beans>
        
        
        public interface TransportClientMonitorGateway {
        	public byte[] send(String text);
        }
        
        public class EchoService {
        	public String test(byte[] bytes) {
        		return "echo:" + new String(bytes);
        	}
        
        }
        Last edited by thehin; Jan 11th, 2011, 02:29 PM.

        Comment


        • #5
          If you are just trying to test the client side, you can just consume messages on the server side with a <stream:stdout-channel-adapter/>. As Oleg implies, though, this configuration implies your gateway method returns void.

          Comment


          • #6
            My previous post was a follow up to my first post.

            This new configuration uses tcp gateways instead of channel adapters.

            As Oleg said, please describe your use case and we can help you with the config.

            Comment


            • #7
              BTW, when posting code or config, please surround it with

              [ code ]

              [ /code ]

              (No spaces inside the brackets).

              Comment


              • #8
                My use case is to have interprocess communication between a Java application running as a service via the Java Service Wrapper and a standalone Java application. I thought using TCP communication between processes would be ideal. I would like a simple command and response, telnet, like communication. I was planning on using JSON text data back and forth between the two processes. If you can suggest a better alternative then I am willing to give that a shot.

                Thanks again.

                Comment


                • #9
                  OK; it was just confusing that you were using channel adapters in the first example, when the sample you cited (from git) uses gateways. So, I assumed you changed them for a reason. Also, not having a consumer for the toSA channel would fail.

                  Your second attempt looks like it should work, but you don't really need the replies channel on the client side, you can let everything default to the reply channel in the outbound message's headers.

                  Can you provide a stack trace of the failure so I can see more details?

                  Comment


                  • #10
                    This is the stack trace I get with the 2nd configuration I had posted above: I noticed the message, "dispatcher has no subscribers.

                    Code:
                    2011-01-11 14:14:19,687  WARN [main] org.springframework.integration.gateway.GatewayProxyFactoryBean$MethodInvocationGateway - failure occurred in gateway sendAndReceive
                    org.springframework.integration.MessageDeliveryException: failed to send Message to channel 'input'
                    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:165)
                    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
                    	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
                    	at org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318)
                    	at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239)
                    	at org.springframework.integration.core.MessagingTemplate.convertSendAndReceive(MessagingTemplate.java:274)
                    	at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:225)
                    	at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:204)
                    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:300)
                    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:269)
                    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:260)
                    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
                    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
                    	at $Proxy0.send(Unknown Source)
                    	at com.company.transport.client.monitor.TransportClientMonitor.run(TransportClientMonitor.java:34)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                    	at java.lang.reflect.Method.invoke(Method.java:616)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
                    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
                    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
                    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
                    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
                    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
                    	at com.company.transport.client.monitor.TransportClientMonitor.main(TransportClientMonitor.java:114)
                    Caused by: java.lang.IllegalStateException: Dispatcher has no subscribers.
                    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:104)
                    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
                    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:44)
                    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
                    	... 33 more

                    Comment


                    • #11
                      I just pasted your tcp config into the tcp sample and it works fine for me.

                      The error you posted makes no sense for the configuration you posted; the error implies there is no consumer for the input channel when, clearly, the outbound gateway consumes those messages (and is born out by my successfully using your config).

                      Are you sure everything you posted is in synch?

                      If you can't figure it out, please post a full debug log of the complete test.

                      Comment


                      • #12
                        Could the fact that I am trying to send to the gateway via an init method (run) be the reason for this? Also I am using SWT. Are there any known issues with Spring Integration and SWT? Thank you so much!

                        I am calling gateway.send("Test") inside of the run method which is an init-method.

                        Code:
                        <beans:bean id="transportClientMonitor" class="com.company.transport.client.monitor.TransportClientMonitor" init-method="run" />
                        To be more precise, I am using an @Autowired gateway and doing gateway.send.

                        Comment


                        • #13
                          Yes, possibly; especially because you are not injecting the gateway into your transportClientMonitor so Spring doesn't know anything about the dependency.

                          I assume you are getting a reference to the gateway using this...

                          Code:
                          <beans:bean id="appContext" class="com.company.transport.util.AppContext" />
                          Why not inject the dependency?

                          Also, I'll have to defer to Mark and Oleg about the wisdom of trying to use SI from within an init-method.

                          Comment


                          • #14
                            Hi Gary,

                            I was originally using the AppContext bean you mentioned to get the dependency. Then I switched to using @Autowired and injected it directly into the class as a field member. Both ways yielded the same result.

                            I figured out the reason as to why it was not working. I am using SWT to create my GUI. I was creating a display via the init-method and this was blocking the thread I suppose. So the gateway initialization could not complete. Once I removed the SWT stuff, everything worked fine. So the initial problem has been resolved however now I have a new problem.

                            How do I use SWT and Spring together. I feel that this forum isn't the appropriate place for that, but feel free to leave any suggestions. Also, are you aware of any other good techniques (using Spring) for interprocess communication?

                            Thanks Again!

                            Comment

                            Working...
                            X