This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

tcp-outbound-gateway - failed to send Message to channelPage Title Module

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

Jan 11th, 2011, 12:28 PM

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.

Comment

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.

Comment

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

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

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

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

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

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.

Comment

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?