spring integration - Exception while sending/receiving msg over TCP using channel adapters -


i getting exception while sending/receiving msg on tcp using channel adapters. trying send message socket using tcpsendingmessagehandler , receive message using tcpreceivingchanneladapter. here able send message getting exception while receiving msgs. please let me know, missing in configuration.

my configuration class:

    public class sampletcpconnection {      //client side     @bean     public messagechannel requestchannel() {         return new directchannel();     }      @conditionalonmissingbean(name = "errorchannel")     @bean     public messagechannel errorchannel() {         return new directchannel();     }       @bean     public bytearraycrlfserializer connectionserializedeserialize(){         return new bytearraycrlfserializer();      }      @bean     @serviceactivator(inputchannel = "requestchannel")     public messagehandler sendtostreamhost() {         tcpsendingmessagehandler gateway = new tcpsendingmessagehandler();         gateway.setconnectionfactory(createconectionfactory());         gateway.setclientmode(true);          return  gateway;     }      @bean     public abstractclientconnectionfactory createconectionfactory(){         abstractclientconnectionfactory cf = new tcpnetclientconnectionfactory("localhost",8002);         cf.setserializer(connectionserializedeserialize());         return cf;     }       @serviceactivator(inputchannel = "fromtcpchannel", outputchannel = "replychannel")     public object replymessage(message<string> msg) {         return msg.getpayload();     }      @serviceactivator(inputchannel = "errorchannel", outputchannel = "replychannel")     public object errormessage(message<string> msg) {         return msg;     }       //server side      @bean     public tcpreceivingchanneladapter tcpingate(abstractserverconnectionfactory connectionfactory)  {         tcpreceivingchanneladapter ingate = new tcpreceivingchanneladapter();         ingate.setconnectionfactory(connectionfactory);         ingate.setoutputchannel(fromtcpsocket());         return ingate;     }      @bean     public abstractserverconnectionfactory createserverconectionfactory(){         abstractserverconnectionfactory cf = new tcpnetserverconnectionfactory(8002);         cf.setserializer(connectionserializedeserialize());         cf.setdeserializer(connectionserializedeserialize());         return cf;     }      @bean     public messagechannel fromtcpsocket() {         return new directchannel();     }      @bean     public messagechannel replychannel() {         return new directchannel();     } } 

my gateway class follows:

@messaginggateway(errorchannel = "errorchannel") public interface clientgateway {      @gateway(requestchannel = "requestchannel", replychannel = "fromtcpsocket")     object sendandrecieve(@headers object customheaders, object object); } 

and invoke gateway this:

    public void handlerequest() {     map<string,object> header = new hashmap<string,object>();     header.put("ip_connectionid", generatecorrelationid());         gateway.sendandrecieve(header,"hello world"); } 

and exception getting following :

            2017-04-06 01:01:59.739 debug 7460 --- [nio-9010-exec-1] o.s.i.ip.tcp.tcpsendingmessagehandler    : got connection localhost:8002:51561:d5c4ef5a-dffd-4e41-b724-600d30c6428a     2017-04-06 01:01:59.751 debug 7460 --- [nio-9010-exec-1] o.s.i.i.tcp.connection.tcpnetconnection  : localhost:8002:51561:d5c4ef5a-dffd-4e41-b724-600d30c6428a message sent genericmessage [payload=hello world, headers={replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@79299208, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@79299208, id=8cd8ff75-a4d3-d5b0-7290-b97e3f86d57c, ip_connectionid=af1ea8793d0cbde0, timestamp=1491420719710}]     2017-04-06 01:01:59.751 debug 7460 --- [nio-9010-exec-1] ssor$replyproducingmessagehandlerwrapper : handler 'tpsconfiguration.sendtostreamhost.serviceactivator.handler' produced no reply request message: genericmessage [payload=hello world, headers={replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@79299208, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@79299208, id=8cd8ff75-a4d3-d5b0-7290-b97e3f86d57c, ip_connectionid=af1ea8793d0cbde0, timestamp=1491420719710}]     2017-04-06 01:01:59.751 debug 7460 --- [nio-9010-exec-1] o.s.integration.channel.directchannel    : postsend (sent=true) on channel 'requestchannel', message: genericmessage [payload=hello world, headers={replychannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@79299208, errorchannel=org.springframework.messaging.core.genericmessagingtemplate$temporaryreplychannel@79299208, id=8cd8ff75-a4d3-d5b0-7290-b97e3f86d57c, ip_connectionid=af1ea8793d0cbde0, timestamp=1491420719710}]     2017-04-06 01:01:59.760 debug 7460 --- [pool-2-thread-1] .s.i.i.t.c.tcpnetserverconnectionfactory : accepted connection 127.0.0.1     2017-04-06 01:01:59.760 debug 7460 --- [pool-4-thread-1] o.s.i.i.tcp.connection.tcpnetconnection  : localhost:8002:51561:d5c4ef5a-dffd-4e41-b724-600d30c6428a reading...     2017-04-06 01:01:59.767 debug 7460 --- [pool-2-thread-1] o.s.i.i.tcp.connection.tcpnetconnection  : new connection 127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f     2017-04-06 01:01:59.767 debug 7460 --- [pool-2-thread-1] .s.i.i.t.c.tcpnetserverconnectionfactory : createserverconectionfactory: added new connection: 127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f     2017-04-06 01:01:59.770 debug 7460 --- [pool-2-thread-2] o.s.i.i.tcp.connection.tcpnetconnection  : 127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f reading...     2017-04-06 01:01:59.773 debug 7460 --- [pool-4-thread-1] o.s.i.i.t.s.bytearraycrlfserializer      : available read:0     2017-04-06 01:01:59.774 debug 7460 --- [pool-2-thread-2] o.s.i.i.t.s.bytearraycrlfserializer      : available read:13     2017-04-06 01:01:59.774 debug 7460 --- [pool-2-thread-2] o.s.b.f.s.defaultlistablebeanfactory     : returning cached instance of singleton bean 'messagebuilderfactory'     2017-04-06 01:01:59.775 debug 7460 --- [pool-2-thread-2] o.s.i.i.tcp.connection.tcpnetconnection  : message received genericmessage [payload=byte[11], headers={ip_tcp_remoteport=51561, ip_connectionid=127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f, ip_localinetaddress=/127.0.0.1, ip_address=127.0.0.1, id=17e75c9d-2cfb-1d0d-4535-db95ceefee50, ip_hostname=127.0.0.1, timestamp=1491420719775}]     2017-04-06 01:01:59.775 debug 7460 --- [pool-2-thread-2] o.s.integration.channel.directchannel    : presend on channel 'xmltostringchannel', message: genericmessage [payload=byte[11], headers={ip_tcp_remoteport=51561, ip_connectionid=127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f, ip_localinetaddress=/127.0.0.1, ip_address=127.0.0.1, id=17e75c9d-2cfb-1d0d-4535-db95ceefee50, ip_hostname=127.0.0.1, timestamp=1491420719775}]     2017-04-06 01:01:59.775 debug 7460 --- [pool-2-thread-2] o.s.i.handler.serviceactivatinghandler   : serviceactivator [org.springframework.integration.handler.methodinvokingmessageprocessor@2e9f7f54] (tpsconfiguration.replymessage.serviceactivator.handler) received message: genericmessage [payload=byte[11], headers={ip_tcp_remoteport=51561, ip_connectionid=127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f, ip_localinetaddress=/127.0.0.1, ip_address=127.0.0.1, id=17e75c9d-2cfb-1d0d-4535-db95ceefee50, ip_hostname=127.0.0.1, timestamp=1491420719775}]     2017-04-06 01:01:59.776 debug 7460 --- [pool-2-thread-2] o.s.b.f.s.defaultlistablebeanfactory     : returning cached instance of singleton bean 'integrationevaluationcontext'     2017-04-06 01:01:59.777 debug 7460 --- [pool-2-thread-2] o.s.b.f.s.defaultlistablebeanfactory     : returning cached instance of singleton bean 'integrationconversionservice'     2017-04-06 01:01:59.781 debug 7460 --- [pool-2-thread-2] o.s.b.f.s.defaultlistablebeanfactory     : returning cached instance of singleton bean 'replychannel'     2017-04-06 01:01:59.781 debug 7460 --- [pool-2-thread-2] o.s.integration.channel.directchannel    : presend on channel 'replychannel', message: genericmessage [payload=byte[11], headers={ip_tcp_remoteport=51561, ip_connectionid=127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f, ip_localinetaddress=/127.0.0.1, ip_address=127.0.0.1, id=9b9eb07f-8829-67c1-e473-644a3d2883b0, ip_hostname=127.0.0.1, timestamp=1491420719781}]     2017-04-06 01:01:59.781 debug 7460 --- [pool-2-thread-2] o.s.integration.handler.bridgehandler    : org.springframework.integration.handler.bridgehandler@586e121d received message: genericmessage [payload=byte[11], headers={ip_tcp_remoteport=51561, ip_connectionid=127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f, ip_localinetaddress=/127.0.0.1, ip_address=127.0.0.1, id=9b9eb07f-8829-67c1-e473-644a3d2883b0, ip_hostname=127.0.0.1, timestamp=1491420719781}]     2017-04-06 01:01:59.788 error 7460 --- [pool-2-thread-2] o.s.i.i.tcp.connection.tcpnetconnection  : exception sending message: genericmessage [payload=byte[11], headers={ip_tcp_remoteport=51561, ip_connectionid=127.0.0.1:51561:8002:61d62f47-77e7-473e-955c-e32585780b6f, ip_localinetaddress=/127.0.0.1, ip_address=127.0.0.1, id=17e75c9d-2cfb-1d0d-4535-db95ceefee50, ip_hostname=127.0.0.1, timestamp=1491420719775}]      org.springframework.messaging.messagingexception: dispatcher failed deliver message; nested exception org.springframework.messaging.core.destinationresolutionexception: no output-channel or replychannel header available         @ org.springframework.integration.dispatcher.abstractdispatcher.wrapexceptionifnecessary(abstractdispatcher.java:133) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.dispatcher.abstractdispatcher.tryoptimizeddispatch(abstractdispatcher.java:120) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.dispatcher.unicastingdispatcher.dodispatch(unicastingdispatcher.java:147) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.dispatcher.unicastingdispatcher.dispatch(unicastingdispatcher.java:120) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.channel.abstractsubscribablechannel.dosend(abstractsubscribablechannel.java:77) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:442) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:392) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.messaging.core.genericmessagingtemplate.dosend(genericmessagingtemplate.java:115) ~[spring-messaging-4.2.6.release.jar:4.2.6.release]         @ org.springframework.messaging.core.genericmessagingtemplate.dosend(genericmessagingtemplate.java:45) ~[spring-messaging-4.2.6.release.jar:4.2.6.release]         @ org.springframework.messaging.core.abstractmessagesendingtemplate.send(abstractmessagesendingtemplate.java:105) ~[spring-messaging-4.2.6.release.jar:4.2.6.release]         @ org.springframework.integration.handler.abstractmessageproducinghandler.sendoutput(abstractmessageproducinghandler.java:231) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractmessageproducinghandler.produceoutput(abstractmessageproducinghandler.java:154) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractmessageproducinghandler.sendoutputs(abstractmessageproducinghandler.java:102) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.handlemessageinternal(abstractreplyproducingmessagehandler.java:105) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractmessagehandler.handlemessage(abstractmessagehandler.java:127) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.dispatcher.abstractdispatcher.tryoptimizeddispatch(abstractdispatcher.java:116) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.dispatcher.unicastingdispatcher.dodispatch(unicastingdispatcher.java:147) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.dispatcher.unicastingdispatcher.dispatch(unicastingdispatcher.java:120) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.channel.abstractsubscribablechannel.dosend(abstractsubscribablechannel.java:77) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:442) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:392) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.messaging.core.genericmessagingtemplate.dosend(genericmessagingtemplate.java:115) ~[spring-messaging-4.2.6.release.jar:4.2.6.release]         @ org.springframework.messaging.core.genericmessagingtemplate.dosend(genericmessagingtemplate.java:45) ~[spring-messaging-4.2.6.release.jar:4.2.6.release]         @ org.springframework.messaging.core.abstractmessagesendingtemplate.send(abstractmessagesendingtemplate.java:105) ~[spring-messaging-4.2.6.release.jar:4.2.6.release]         @ org.springframework.integration.endpoint.messageproducersupport.sendmessage(messageproducersupport.java:105) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.ip.tcp.tcpreceivingchanneladapter.onmessage(tcpreceivingchanneladapter.java:87) ~[spring-integration-ip-4.2.5.release.jar:na]         @ org.springframework.integration.ip.tcp.connection.tcpnetconnection.run(tcpnetconnection.java:182) ~[spring-integration-ip-4.2.5.release.jar:na]         @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) [na:1.8.0_40]         @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) [na:1.8.0_40]         @ java.lang.thread.run(thread.java:745) [na:1.8.0_40]     caused by: org.springframework.messaging.core.destinationresolutionexception: no output-channel or replychannel header available         @ org.springframework.integration.handler.abstractmessageproducinghandler.sendoutput(abstractmessageproducinghandler.java:226) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractmessageproducinghandler.produceoutput(abstractmessageproducinghandler.java:154) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractmessageproducinghandler.sendoutputs(abstractmessageproducinghandler.java:102) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.handlemessageinternal(abstractreplyproducingmessagehandler.java:105) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.handler.abstractmessagehandler.handlemessage(abstractmessagehandler.java:127) ~[spring-integration-core-4.2.5.release.jar:na]         @ org.springframework.integration.dispatcher.abstractdispatcher.tryoptimizeddispatch(abstractdispatcher.java:116) ~[spring-integration-core-4.2.5.release.jar:na]         ... 28 common frames omitted      2017-04-06 01:01:59.788 debug 7460 --- [pool-2-thread-2] o.s.i.i.t.s.bytearraycrlfserializer      : available read:0 

you should consider use tcpoutboundgateway such scenario.

the tcpreceivingchanneladapter , tcpsendingmessagehandler using different sockets , there no replychannel information in incoming message.

on other hand see mess in config. declare client , server in same context. meanwhile doesn't hurt, can't applied @messaginggateway config. see here: send message client and, yes, receive in server, problem try dispatch @messaginggateway reply. confused...

please, read more spring integration reference manual understand how @messaginggateway , tcp channel adapters work.


Comments