为TcpOutboundGateway连接到旧服务器

时间:2015-05-18 14:52:01

标签: java spring-boot spring-integration

我的理解是TcpOutboundGateway正在关联tcp请求和响应,但我不知道如何使用它。

下面的代码段通过TcpOutboundGateway发送消息,以便与旧系统进行通信。

message = new GenericMessage("ccs?cmd=5&itm="+(16600+t)+"&rf=2");
Test.sendChannel.send(message); // sendChannel is a DirectChannel. 
//Blocks here until reply comes in (in single use and cached)

我有一个端点来处理响应:

@ServiceActivator(inputChannel = "replyChannel")
public void handleReply(byte[] rawRes) {
    // handle the reply.
}

handleReply(...)需要在代码中的发送点提供上下文,反之亦然。使用Threadlocal将上下文传递给处理程序会起作用(在这种情况下),但似乎是一个坏主意。

我已经查看了这些示例,但它们看起来与我的代码完全不同(我认为因为我正在使用Spring启动)所以请提前道歉 - 我确信我忽略了显而易见的事情,但我会感激一些帮助。

1 个答案:

答案 0 :(得分:0)

您可以在MessageHeaders requestMessage内携带上下文,replyMessage将提供来自请求的标头。

对于replyChannel上的POJO处理程序,您可以使用@Header("myContext")添加一个方法参数。