【问题标题】:Not able to send data on reply channel using tcp-outbound-gateway with ActiveMQ无法使用带有 ActiveMQ 的 tcp-outbound-gateway 在回复通道上发送数据
【发布时间】:2018-03-23 12:50:38
【问题描述】:

我的要求是从 TCP 获取数据,从 TCP 获取数据后转换为 java 对象并在 ActiveMQ 上发送。发布后,需要在 TCP 上的同一通道上发送确认/响应代码。 为了满足这个要求,我使用 tcp-outbound-gateway 作为双向通信。

问题是我无法使用 ActiveMQ 发送确认。如果我注释掉 ActiveMQ 部分并在 replyChannel 上写一个虚拟字符串,它是可见的,但是当我在 Active MQ 队列上发送对象时,它会给我一条消息“收到空回复,没有发送任何内容” .

我正在使用一个新队列来获取确认并尝试将响应放在 tcp-outbound-gate 的回复通道上,但错误消息是 没有可用的输出通道或回复通道标头。 em>

我通过传入消息获得了 MessageHeaders 详细信息,并通过队列发送它以使用 copyHeader。我可以设置标头并在 Message 对象中查看 paylod,通过在回复通道上应用 Interceptos 验证相同,但仍然收到相同的错误 没有可用的输出通道或回复通道标头。

代码是:

<int:gateway id="gw" default-reply-channel="replyChannel" default-reply-timeout="10000" service-interface= "com.telnet.core.integration.connection.ParseTcpConfiguration$SimpleGateway"
default-request-channel="${server.inboundChannel}"/>

<int:channel id="telnetLandingChannel" />

<ip:tcp-connection-factory id="serverFactory" type="server"  host="${server.host}" port="${server.port}" single-use="false"
serializer="${server.serializer}" deserializer="${server.serializer}" task-executor="serverFactoryTaskExecutor"/>

<ip:tcp-inbound-gateway id="serverInboundAdpater"   request-channel="telnetLandingChannel"  reply-channel="replyChannel"
connection-factory="serverFactory"  error-channel="errorChannel"    reply-timeout="1000000" auto-startup="false"/>    

<int:channel id="replyChannel"></int:channel>

<beans:bean id="acknowledgementHandler"     class= "com.telnet.core.integration.AcknowledgementHandler">
</beans:bean>

<int:channel id="incidentDispatchMessageChannel" datatype="${incident.interaction.dispatch.response.datatype}"></int:channel>

<int-jms:message-driven-channel-adapter id="incidentDispatchMessageChannelAdapter" error-channel="errorChannel"
connection-factory="mqConnectionFactory"
destination-name="${incident.processing.tcp.dispatch.response.queues}" 
channel="incidentDispatchMessageChannel"/>

<int:transformer id="incidentMessageActivator" 
input-channel="incidentDispatchMessageChannel" 
output-channel="replyChannel"
ref="acknowledgementHandler" method="incidentAck">
</int:transformer>    

public Message incidentAck(final DefaultIncidentAcknowledgeMessage defaultIncidentAcknowledgeMessage){

    MessageHeaders ms = (MessageHeaders)defaultIncidentAcknowledgeMessage.getProperties().get("MessageHeader");
    Message<String> message = MessageBuilder.withPayload("1").copyHeaders(ms).build();
    return message;
}

【问题讨论】:

    标签: tcp spring-integration activemq


    【解决方案1】:

    虽然需要查看您的集成配置,但我猜您在 replyChannel 标头中丢失了 TemporaryReplyChannel 对象,因为它不是 Serializable。考虑使用:

    <int:header-enricher>
        <int:header-channels-to-string/>
    </int:header-enricher>
    

    发送到 ActveMQ 之前的某处。

    更多信息请参见Reference Manual

    更新

    看起来这是Receive the acknowledgement from TCP server to our application using spring Integration 的延续。我看到你在很多地方仍然使用相同的replyChannel。那将无法正常工作。来自网关的replyChannel 标头只能接受一个回复。即使我们知道如何处理来自 ActiveMQ 的回复,TemporaryReplyChannel 也将通过来自 TCP 出站网关的回复来完成。

    如果我理解正确,除了来自 TCP 的回复之外,您还需要从 ActiveMQ 获得一些消息。并将所有内容作为对网关呼叫的回复发送。为此,我建议您考虑使用聚合器并找出一些自定义关联策略来匹配来自 TCP 的回复与来自 ActiveMQ 的确认。聚合后,你真的可以只使用现有的replyChannel 标头来回复网关。

    【讨论】:

    • 我需要在哪个频道上使用 header-enricher
    • 如果没有在 ActiceMQ 上发送消息,我可以看到确认。看起来网关无法在回复通道上获得任何回复或通道已关闭。在 Active MQ 的情况下,是否有任何不同的方式来处理需要在网关上发送的回复。现在由于 Active MQ,现在它不是同步调用。
    • 在我的回答中查看更新
    • 我使用了更改通道名称并发布了使用现有代码而不是入站网关添加入站适配器和出站适配器的帖子,并且效果很好。
    • 由于我的代码调用是异步概率,这就是为什么我无法使用网关的回复通道获得回复的原因。我不太了解异步网关,因为它通常以同步方式工作,如何在异步模式下使用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 2018-04-11
    • 2020-09-03
    • 2016-01-16
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    相关资源
    最近更新 更多