Spring 与 Citrus 集成:没有 output-channel 或 replyChannel header 可用
Spring integration with Citrus: no output-channel or replyChannel header available
我已经配置了一个测试,我首先从服务器发送 "Req" 到我的应用程序,然后用 "Rsp" 响应服务器。我成功收到请求消息,但在尝试响应时出现以下错误:
org.springframework.messaging.MessagingException: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
at org.springframework.integration.dispatcher.AbstractDispatcher.wrapExceptionIfNecessary(AbstractDispatcher.java:133)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:120)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at com.consol.citrus.channel.ChannelProducer.send(ChannelProducer.java:66)
at com.consol.citrus.actions.SendMessageAction.doExecute(SendMessageAction.java:103)
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
at com.consol.citrus.TestCase.executeAction(TestCase.java:211)
... 31 more
Caused by: org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:226)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
... 57 more
请在下面查看我的 bean 配置:
citrus-config.xml
<citrus:channel-endpoint id="citrusServiceReqEndpoint"
channel-name="req_transformed" />
<citrus:channel-endpoint id="citrusServiceRspEndpoint"
channel-name="rsp" />
<int-ip:tcp-connection-factory id="client"
type="client" host="localhost" port="12345" single-use="false"
so-timeout="10000" using-nio="true" deserializer="javaSerializer"
serializer="javaSerializer" />
<bean id="javaSerializer"
class="org.springframework.integration.ip.tcp.serializer.ByteArrayLfSerializer" />
<int:channel id="req" />
<int:channel id="req_transformed">
<int:queue />
</int:channel>
<int:channel id="rsp">
</int:channel>
<int:channel id="rsp_transformed">
</int:channel>
<int:object-to-string-transformer id="incomingTransformer" input-channel="req" output-channel="req_transformed" />
<int:object-to-string-transformer id="outgoingTransformer" input-channel="rsp" output-channel="rsp_transformed" />
<int-ip:tcp-inbound-gateway id="gateway"
connection-factory="client"
request-channel="req"
reply-channel="rsp_transformed"
client-mode="true" />
测试用例:
receive("citrusServiceReqEndpoint").messageType(MessageType.PLAINTEXT).payload("Req");
send("citrusServiceRspEndpoint").payload("Rsp");
receive("citrusServiceReqEndpoint").messageType(MessageType.PLAINTEXT).payload("Req2");
send("citrusServiceRspEndpoint").payload("Rsp2");
基本上,我的意图是在 "req" 通道上接收数据,然后将字节转换为字符串到 req_transformed 通道,然后验证字符串是否等于 "Req".然后,我想发回一个 "Rsp" 字符串,将其转换为字节,然后放入 rsp_transformed 通道作为回复。
请帮助我了解问题所在。请注意,当我用两个通道适配器替换 tcp-inbound-gateway 时:
<int-ip:tcp-outbound-channel-adapter
id="outboundClient" channel="rsp" connection-factory="client" />
<int-ip:tcp-inbound-channel-adapter
id="inboundClient" channel="req" connection-factory="client" client-mode="true" />
测试用例 100% 有效。为什么它不能与网关一起使用?
我不熟悉柑橘,但在使用网关时,响应必须包含来自请求的某些 headers - 特别是在这种情况下的 replyChannel
header - 就是这样网关知道回复的是哪个请求(可能有很多并发请求通过网关)。
您可以使用一对 collaborating TCP inbound/outbound channel adapters 而不是入站网关,但是您仍然需要通过传播 ip_connectionId
[=17= 来告诉出站适配器回复是针对哪个套接字的] 从请求到回复。
您的 tcp-inbound-gateway 使用同步消息传递。因此,您需要相应地在 Citrus 中使用同步通道端点。
<citrus:channel-sync-endpoint id="citrusServiceSyncEndpoint"
channel-name="req_transformed"/>
同步端点将处理将 req/resp 通道与 request/reply 关联的特殊 headers。所以你的测试看起来像这样:
receive("citrusServiceSyncEndpoint")
.messageType(MessageType.PLAINTEXT)
.payload("Req");
send("citrusServiceSyncEndpoint")
.messageType(MessageType.PLAINTEXT)
.payload("Rsp");
请注意请求和响应使用同一个同步端点。
我已经配置了一个测试,我首先从服务器发送 "Req" 到我的应用程序,然后用 "Rsp" 响应服务器。我成功收到请求消息,但在尝试响应时出现以下错误:
org.springframework.messaging.MessagingException: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
at org.springframework.integration.dispatcher.AbstractDispatcher.wrapExceptionIfNecessary(AbstractDispatcher.java:133)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:120)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
at com.consol.citrus.channel.ChannelProducer.send(ChannelProducer.java:66)
at com.consol.citrus.actions.SendMessageAction.doExecute(SendMessageAction.java:103)
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
at com.consol.citrus.TestCase.executeAction(TestCase.java:211)
... 31 more
Caused by: org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:226)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
... 57 more
请在下面查看我的 bean 配置: citrus-config.xml
<citrus:channel-endpoint id="citrusServiceReqEndpoint"
channel-name="req_transformed" />
<citrus:channel-endpoint id="citrusServiceRspEndpoint"
channel-name="rsp" />
<int-ip:tcp-connection-factory id="client"
type="client" host="localhost" port="12345" single-use="false"
so-timeout="10000" using-nio="true" deserializer="javaSerializer"
serializer="javaSerializer" />
<bean id="javaSerializer"
class="org.springframework.integration.ip.tcp.serializer.ByteArrayLfSerializer" />
<int:channel id="req" />
<int:channel id="req_transformed">
<int:queue />
</int:channel>
<int:channel id="rsp">
</int:channel>
<int:channel id="rsp_transformed">
</int:channel>
<int:object-to-string-transformer id="incomingTransformer" input-channel="req" output-channel="req_transformed" />
<int:object-to-string-transformer id="outgoingTransformer" input-channel="rsp" output-channel="rsp_transformed" />
<int-ip:tcp-inbound-gateway id="gateway"
connection-factory="client"
request-channel="req"
reply-channel="rsp_transformed"
client-mode="true" />
测试用例:
receive("citrusServiceReqEndpoint").messageType(MessageType.PLAINTEXT).payload("Req");
send("citrusServiceRspEndpoint").payload("Rsp");
receive("citrusServiceReqEndpoint").messageType(MessageType.PLAINTEXT).payload("Req2");
send("citrusServiceRspEndpoint").payload("Rsp2");
基本上,我的意图是在 "req" 通道上接收数据,然后将字节转换为字符串到 req_transformed 通道,然后验证字符串是否等于 "Req".然后,我想发回一个 "Rsp" 字符串,将其转换为字节,然后放入 rsp_transformed 通道作为回复。
请帮助我了解问题所在。请注意,当我用两个通道适配器替换 tcp-inbound-gateway 时:
<int-ip:tcp-outbound-channel-adapter
id="outboundClient" channel="rsp" connection-factory="client" />
<int-ip:tcp-inbound-channel-adapter
id="inboundClient" channel="req" connection-factory="client" client-mode="true" />
测试用例 100% 有效。为什么它不能与网关一起使用?
我不熟悉柑橘,但在使用网关时,响应必须包含来自请求的某些 headers - 特别是在这种情况下的 replyChannel
header - 就是这样网关知道回复的是哪个请求(可能有很多并发请求通过网关)。
您可以使用一对 collaborating TCP inbound/outbound channel adapters 而不是入站网关,但是您仍然需要通过传播 ip_connectionId
[=17= 来告诉出站适配器回复是针对哪个套接字的] 从请求到回复。
您的 tcp-inbound-gateway 使用同步消息传递。因此,您需要相应地在 Citrus 中使用同步通道端点。
<citrus:channel-sync-endpoint id="citrusServiceSyncEndpoint"
channel-name="req_transformed"/>
同步端点将处理将 req/resp 通道与 request/reply 关联的特殊 headers。所以你的测试看起来像这样:
receive("citrusServiceSyncEndpoint")
.messageType(MessageType.PLAINTEXT)
.payload("Req");
send("citrusServiceSyncEndpoint")
.messageType(MessageType.PLAINTEXT)
.payload("Rsp");
请注意请求和响应使用同一个同步端点。