Spring 为 NAT 后面的客户端集成 UDP 服务器

Spring Integration UDP server for clients behind NAT

我尝试使用 Spring 集成来实现 UDP 服务器,就像描​​述的那样 here but when clients operate behind NAT they will never receive responses from server. It's because server should send response datagrams from the same port as UDP adapter port (check UDP via NAT explained here)。

如何使用 Spring 集成与 NAT 后面的客户端实现正确的 UDP 通信?

正如那些话题中所讨论的那样;当前没有任何 UDP 网关,只有通道适配器。网关用于 two-way 集成。

多年来对 UDP 网关没有任何需求。

我们做了 make some changes 以方便用户回复收到的消息(通过将发送端口添加为 header)。

这将允许您构建一个 DatagramPacket(可能使用 SI DatagramPacketMessageMapper)并使用您自己的代码将其发送到原始系统。

如果您希望我们重新考虑提供 UDP 网关,请在 JIRA Issue. Even better, consider contributing 上发表评论。

编辑

对于异步发送,您不需要网关;购买你需要调整内置在出站适配器中的映射器和消息处理程序。

更改 DatagramPacketMessageMapper here to set the socketAddress using message headers; and add an option to the UnicastSendingMessageHandler so that it doesn't unconditionally set the destinationAddress here

您可以通过继承处理程序并覆盖 send() 方法来实现。

然后您可以使用 ref 属性将自定义消息处理程序连接到 <service-activator/>