【问题标题】:what is equivalent of <tcp-outbound-channel-adapter> in java config?java config 中的 <tcp-outbound-channel-adapter> 等价物是什么?
【发布时间】:2015-05-03 19:49:57
【问题描述】:

我有以下 bean 的 spring 集成 XML 配置

<int-ip:tcp-outbound-channel-adapter id="outboundClient"
channel="input"
connection-factory="client"/>

我认为 java config 中的等价物是

@ServiceActivator(inputChannel = "input", requiresReply = "true")
public TcpSendingMessageHandler outboundClient() {
    TcpSendingMessageHandler tcpSendingMessageHandler = new TcpSendingMessageHandler();
    tcpSendingMessageHandler.setConnectionFactory(clientConnectionFactory());
    tcpSendingMessageHandler.setRetryInterval(10000);
    tcpSendingMessageHandler.setClientMode(true);
    return tcpSendingMessageHandler;
}

但是,在日志中,我看到了

TcpListener exiting - no listener and not single use

我无法收到服务器的回复。

感谢任何帮助

【问题讨论】:

    标签: java spring spring-integration spring-java-config


    【解决方案1】:

    TcpSendingMessageHandler 用于单向使用 - 仅用于向 TCP 套接字发送消息。

    所以,您的配置看起来不错,在我看来它应该可以工作。

    TcpListener 退出 - 没有监听器,也不是单次使用

    只是来自TcpNetConnection 的DEBUG 消息,表明您的组件是one-way。

    所以收不到服务器的回复是正常的。因为你只向那里发送消息。

    要让request/reply 场景考虑使用TcpOutboundGateway。

    【讨论】:

    • 谢谢@artem-bilan。但是在 spring 集成文档中,提到了:The gateways will automatically correlate messages. However, an outbound gateway should only be used for relatively low-volume use. Therefore, for high-volume messages, consider using a collaborating pair of channel adapters. However, you will need to provide collaboration logic.
    • 然后?这是正确的。要从服务器接收消息,您必须添加&lt;int-ip:tcp-inbound-channel-adapter&gt;。并注意:只接收。所以,他们正是合作的一对。但是,是的,它们不是关联的自动逻辑,因此您应该自己支持它。
    • 所以我已经放置了入站通道适配器,但是我得到了no output-channel or replyChannel header available。标头是否也被序列化并通过网络发送?
    • 是的,有可能:&lt;header-channels-to-string&gt; (docs.spring.io/spring-integration/docs/latest-ga/reference/html/…)
    • 但即使这样也行不通,因为 TCP 没有标准的方式来传送标头;您需要将它们添加到消息有效负载中。我们确实提供了mechanism for that,但它仅在另一方也是 Spring Integration 时才有效(或理解标题并在回复中返回它们)。解决网关性能问题的另一种方法是使用caching client factory。
    猜你喜欢
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 2015-10-18
    • 2021-10-18
    • 2010-12-07
    • 2013-03-12
    • 2014-12-06
    • 2011-06-05
    相关资源
    最近更新 更多