我使用cusctom serialzer和deserialzer创建了一个带有SI的Tcpclient,它将字符串“kksingh”的序列化字节数组发送到服务器,并接收响应作为字节数组,反序列化回到字符串。我能够向服务器发送请求,但是我无法得到回应。 但它在日志中显示来自池的thread1已收到消息但我的主线程无法获取它。 我的TcpClientclass
public final class Main
{
/**
* Prevent instantiation.
*/
private Main()
{
}
/**
* Load the Spring Integration Application Context
*
* @param args
* - command line arguments
*/
public static void main(final String... args)
{
System.out.println("\n========================================================="
+ "\n "
+ "\n Welcome to the Spring Integration "
+ "\n TCP-Client-Server Sample! "
+ "\n "
+ "\n For more information please visit: "
+ "\n http://www.springintegration.org/ "
+ "\n "
+ "\n=========================================================");
final GenericXmlApplicationContext context = Main.setupContext();
final SimpleGateway gateway = context.getBean(SimpleGateway.class);
System.out.println("Please enter some text and press <enter>: ");
System.out.println("\tNote:");
System.out.println("\t- Entering FAIL will create an exception");
System.out.println("\t- Entering q will quit the application");
System.out.print("\n");
System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests.");
System.out.println("main" + Thread.currentThread().getName());
final String msg = gateway.send("kksingh");
System.out.println(Thread.currentThread().getName() + "---response--" + msg);
System.out.println("Exiting application...bye.");
System.exit(0);
}
public static GenericXmlApplicationContext setupContext()
{
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml");
context.registerShutdownHook();
context.refresh();
return context;
}
}
Gatewayinterface
public interface SimpleGateway {
public String send(String text);
}
Custom serialzer and deserialzer
public class UCCXImprovedSerializer implements Serializer<String>, Deserializer<String>
{
@Override
public String deserialize(InputStream initialStream) throws IOException
{
byte binput[] = new byte[initialStream.available()];
initialStream.read(binput);
String target = new String(binput);
System.out.println(Thread.currentThread().getName() + "---reply deserialize----" + target);
return target;
}
@Override
public void serialize(String msg, OutputStream os) throws IOException
{
System.out.println(msg + "---serialize---" + Thread.currentThread().getName());
os.write(msg.getBytes());
}
}
我的clientserverdemo-context.xml:
<bean id="UCCXImprovedSerializerDeserialier"
class="org.springframework.integration.samples.tcpclientserver.UCCXImprovedSerializer" />
<int:gateway id="gw"
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"/>
<int:channel id="input" />
<int-ip:tcp-connection-factory id="client"
type="client" host="localhost" port="9999" single-use="true"
serializer="UCCXImprovedSerializerDeserialier"
deserializer="UCCXImprovedSerializerDeserialier" mapper="mapper" />
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input" connection-factory="client" request-timeout="10000"/>
<bean id="mapper"
class="org.springframework.integration.samples.tcpclientserver.CustomMapper">
</bean>
</beans>
有时输出
kksingh---serialize---main
00:00:10.690 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c Message sent GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, id=d6332cbd-24b0-4300-eb9e-f2a5e7b07148, timestamp=1496514610673}]
00:00:10.691 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c Reading...
pool-1-thread-1---reply deserialize----kksingh
00:00:10.692 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'messageBuilderFactory'
00:00:10.692 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message
received GenericMessage [payload=kksingh, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=b14c7c14-dde6-551d-0cd0-5fa71af42ead, ip_hostname=localhost, timestamp=1496514610692}]
pool-1-thread-1---reply deserialize----
00:00:10.693 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Response GenericMessage [payload=kksingh, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=b14c7c14-dde6-551d-0cd0-5fa71af42ead, ip_hostname=localhost, timestamp=1496514610692}]
00:00:10.693 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Removed pending reply localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c
00:00:10.696 [main] DEBUG org.springframework.integration.channel.DirectChannel - preSend on channel 'output', message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=32afced5-e1dd-9b93-4407-e7e48087f333, ip_hostname=localhost, timestamp=1496514610696}]
00:00:10.699 [main] DEBUG org.springframework.integration.handler.BridgeHandler - org.springframework.integration.handler.BridgeHandler@4e3958e7 received message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=32afced5-e1dd-9b93-4407-e7e48087f333, ip_hostname=localhost, timestamp=1496514610696}]
00:00:10.700 [main] DEBUG org.springframework.integration.channel.DirectChannel - postSend (sent=true) on channel 'output', message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.cor`enter code here`e.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:49662:ff770a35-0e6c-401a-a79d-14439ccf345c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=32afced5-e1dd-9b93-4407-e7e48087f333, ip_hostname=localhost, timestamp=1496514610696}]
00:00:10.701 [main] DEBUG org.springframework.integration.channel.DirectChannel - postSend (sent=true) on channel 'input', message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, id=d6332cbd-24b0-4300-eb9e-f2a5e7b07148, timestamp=1496514610673}]
00:00:10.701 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationConversionService'
main---response--kksingh
Exiting application...bye.
输出有时候
mainmain
00:10:25.227 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationGlobalProperties'
00:10:25.227 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'messageBuilderFactory'
00:10:25.227 [main] INFO org.springframework.integration.endpoint.EventDrivenConsumer - Adding {bridge:null} as a subscriber to the 'output' channel
00:10:25.227 [main] INFO org.springframework.integration.channel.DirectChannel - Channel 'org.springframework.context.support.GenericXmlApplicationContext@cac736f.output' has 1 subscriber(s).
00:10:25.227 [main] INFO org.springframework.integration.endpoint.EventDrivenConsumer - started org.springframework.integration.endpoint.EventDrivenConsumer@bccb269
00:10:25.228 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationEvaluationContext'
00:10:25.234 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationGlobalProperties'
00:10:25.235 [main] DEBUG org.springframework.integration.channel.DirectChannel - preSend on channel 'input', message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, id=f43023da-3596-8cf2-4439-45496c087cd9, timestamp=1496515225235}]
00:10:25.235 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - org.springframework.integration.ip.tcp.TcpOutboundGateway#0 received message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, id=f43023da-3596-8cf2-4439-45496c087cd9, timestamp=1496515225235}]
00:10:25.235 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory - Opening new socket connection to localhost:9999
00:10:25.244 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - New connection localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c
00:10:25.244 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory - client: Added new connection: localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c
00:10:25.245 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c Reading...
pool-1-thread-1---reply deserialize----
00:10:25.246 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'messageBuilderFactory'
00:10:25.246 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=008f25f9-2a8f-8bf7-b960-d9c9ff6c4d5e, ip_hostname=localhost, timestamp=1496515225246}]
00:10:25.246 [pool-1-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply for localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c
pool-1-thread-1---reply deserialize----
00:10:25.247 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=309799b8-f7fc-775c-2ded-d78d4106aa3c, ip_hostname=localhost, timestamp=1496515225247}]
00:10:25.247 [pool-1-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply for localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c
pool-1-thread-1---reply deserialize----
00:10:25.247 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=52f47f78-f278-714d-0883-5e0d55930a2e, ip_hostname=localhost, timestamp=1496515225247}]
00:10:25.247 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Added pending reply localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c
pool-1-thread-1---reply deserialize----
kksingh---serialize---main
00:10:25.247 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=b2ba4463-6b41-3706-c4da-ef2f8244ac63, ip_hostname=localhost, timestamp=1496515225247}]
pool-1-thread-1---reply deserialize----
00:10:25.248 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c Message sent GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, id=f43023da-3596-8cf2-4439-45496c087cd9, timestamp=1496515225235}]
00:10:25.248 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Response GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=52f47f78-f278-714d-0883-5e0d55930a2e, ip_hostname=localhost, timestamp=1496515225247}]
00:10:25.248 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Removed pending reply localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c
00:10:25.248 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=87bc891c-1067-1e79-79ec-3c203641cff4, ip_hostname=localhost, timestamp=1496515225248}]
00:10:25.248 [pool-1-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply for localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c
00:10:25.249 [main] DEBUG org.springframework.integration.channel.DirectChannel - preSend on channel 'output', message: GenericMessage [payload=, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=af31dde1-93ec-7209-b3c0-1c4d4e0a4949, ip_hostname=localhost, timestamp=1496515225249}]
00:10:25.249 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Read exception localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c SocketException:Socket is closed
00:10:25.249 [main] DEBUG org.springframework.integration.handler.BridgeHandler - org.springframework.integration.handler.BridgeHandler@37883b97 received message: GenericMessage [payload=, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=af31dde1-93ec-7209-b3c0-1c4d4e0a4949, ip_hostname=localhost, timestamp=1496515225249}]
00:10:25.249 [main] DEBUG org.springframework.integration.channel.DirectChannel - postSend (sent=true) on channel 'output', message: GenericMessage [payload=, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:50603:200af55e-020e-4334-ab34-d00ccd9ff43c, ip_localInetAddress=/127.0.0.1, ip_address=127.0.0.1, id=af31dde1-93ec-7209-b3c0-1c4d4e0a4949, ip_hostname=localhost, timestamp=1496515225249}]
00:10:25.249 [main] DEBUG org.springframework.integration.channel.DirectChannel - postSend (sent=true) on channel 'input', message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7ee8290b, id=f43023da-3596-8cf2-4439-45496c087cd9, timestamp=1496515225235}]
00:10:25.250 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationConversionService'
main---response--
Exiting application...bye.
我更新的custommapper类
public class CustomMapper extends TcpMessageMapper
{
@Override
protected Map<String, ?> supplyCustomHeaders(TcpConnection connection)
{
Map<String, String> temp = new HashMap<>();
temp.put("correlationId", connection.getConnectionId());
System.out.println("correlationId--" + connection.getConnectionId());
return temp;
}
}
现在我的更新日志正在显示
mainmain
20:30:13.170 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationEvaluationContext'
20:30:13.176 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationGlobalProperties'
20:30:13.177 [main] DEBUG org.springframework.integration.channel.DirectChannel - preSend on channel 'input', message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, id=c1c3b4e3-84bc-11d1-1ad7-1ffd33fed55e, timestamp=1496588413177}]
20:30:13.177 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - org.springframework.integration.ip.tcp.TcpOutboundGateway#0 received message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, id=c1c3b4e3-84bc-11d1-1ad7-1ffd33fed55e, timestamp=1496588413177}]
20:30:13.177 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory - Opening new socket connection to localhost:9999
20:30:13.186 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - New connection localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.186 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory - client: Added new connection: localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.187 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b Reading...
pool-1-thread-1---deserialize----
20:30:13.188 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'messageBuilderFactory'
correlationId--localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.188 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Added pending reply localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.189 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_localInetAddress=/127.0.0.1, correlationId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_address=127.0.0.1, id=97276838-77fc-30e1-c1b5-ec31f4d43a9f, ip_hostname=localhost, timestamp=1496588413188}]
pool-1-thread-1---deserialize----
kksingh---serialize---main
correlationId--localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.189 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_localInetAddress=/127.0.0.1, correlationId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_address=127.0.0.1, id=b4dc9909-2a10-2e7f-fa25-1f88311b99c2, ip_hostname=localhost, timestamp=1496588413189}]
pool-1-thread-1---deserialize----kksingh
correlationId--localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.191 [main] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b Message sent GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, id=c1c3b4e3-84bc-11d1-1ad7-1ffd33fed55e, timestamp=1496588413177}]
20:30:13.191 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=kksingh, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_localInetAddress=/127.0.0.1, correlationId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_address=127.0.0.1, id=3a3016c1-ea89-46b8-56a7-a549d94c529b, ip_hostname=localhost, timestamp=1496588413191}]
20:30:13.191 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Response GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_localInetAddress=/127.0.0.1, correlationId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_address=127.0.0.1, id=97276838-77fc-30e1-c1b5-ec31f4d43a9f, ip_hostname=localhost, timestamp=1496588413188}]
pool-1-thread-1---deserialize----
correlationId--localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.192 [main] DEBUG org.springframework.integration.ip.tcp.TcpOutboundGateway - Removed pending reply localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.192 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Message received GenericMessage [payload=, headers={ip_tcp_remotePort=9999, ip_connectionId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_localInetAddress=/127.0.0.1, correlationId=localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b, ip_address=127.0.0.1, id=269e9644-011e-934b-006d-032b76da146b, ip_hostname=localhost, timestamp=1496588413192}]
20:30:13.192 [pool-1-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply for localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b
20:30:13.193 [pool-1-thread-1] DEBUG org.springframework.integration.ip.tcp.connection.TcpNetConnection - Read exception localhost:9999:61953:d06b7c55-aa38-4e7d-ab3e-fd82e477812b SocketException:Socket is closed
20:30:13.193 [main] DEBUG org.springframework.integration.channel.DirectChannel - postSend (sent=true) on channel 'input', message: GenericMessage [payload=kksingh, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1190200a, id=c1c3b4e3-84bc-11d1-1ad7-1ffd33fed55e, timestamp=1496588413177}]
20:30:13.193 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationConversionService'
main---response--
Exiting application...bye.
我的服务器类很简单
echoServer = new ServerSocket(9999);
clientSocket = echoServer.accept();
System.out.println("client connection established..");
is = new DataInputStream(clientSocket.getInputStream());
os = new PrintStream(clientSocket.getOutputStream());
// As long as we receive data, echo that data back to the client.
String tempString = "kksingh";
byte[] tempStringByte = tempString.getBytes();
byte[] temp = new byte[tempString.getBytes().length];
while (true)
{
is.read(temp);
System.out.println(new String(temp) + "--received byte is--- ");
System.out.println("sending value");
os.write(tempStringByte);
break;
}
请告诉我如何让主线程总是等待来自服务器的响应使用自定义序列化器和desrialzer PS:我是春季整合新手。
答案 0 :(得分:0)
你的
final String msg = gateway.send("kksingh");
调用已经是同步方法调用。并且线程将不会进入下一个操作,直到返回此操作。这就是Java和任何其他语言的工作方式。这与潜在的呼叫如何运作无关。
是的,您在日志中看到的意味着在侦听线程中收到了回复,但主线程被阻止,因为我们正在等待回复条件。