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

Thread: tcp-outbound-gateway - failed to send Message to channel

  1. #1
    Join Date
    Jan 2011
    Posts
    6

    Default 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 at 01:30 PM.

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    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?

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

    Default

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

  4. #4
    Join Date
    Jan 2011
    Posts
    6

    Default

    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 at 01:29 PM.

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

    Default

    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.

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

    Default

    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.

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

    Default

    BTW, when posting code or config, please surround it with

    [ code ]

    [ /code ]

    (No spaces inside the brackets).

  8. #8
    Join Date
    Jan 2011
    Posts
    6

    Default

    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.

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

    Default

    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?

  10. #10
    Join Date
    Jan 2011
    Posts
    6

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •