Spring Integration 中的 @Router 与注释(请求/回复)

crm*_*m86 2 integration spring router annotations spring-integration

您能提供在 Spring Integration 中路由消息的任何示例吗?按有效负载消息、标头或类似以下内容进行过滤:

<int:payload-type-router input-channel="routingChannel">
<int:mapping type="java.lang.String"  channel="channel1" />
<int:mapping type="java.lang.Integer" channel="channel2" />
</int:payload-type-router>
Run Code Online (Sandbox Code Playgroud)

响应如何发挥作用?我的意思是,如果我发送:

通道->路由器->变压器->网关

很简单,但我正在寻找类似于此示例的内容:

<int:router input-channel="inChannel" expression="payload.paymentType">
<int:mapping value="CASH" channel="cashPaymentChannel"/>
<int:mapping value="CREDIT" channel="authorizePaymentChannel"/>
<int:mapping value="DEBIT" channel="authorizePaymentChannel"/>
</int:router>
Run Code Online (Sandbox Code Playgroud)

当我的网关收到消息并将响应发送到回复通道时。我如何在路由器中得知正确的回复通道是什么?

Gar*_*ell 5

@Router方法只是返回消息将路由到的通道或通道名称。

@Router(inputChannel="routingChannel")
public String route(Object payload) {
    if (payload instanceof String() {
        return "channel1";
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

对于你的第二个问题,你需要展示更多的流程;什么是“上游” channel

您可以省略reply-channel来自网关的 (或省略output-channel来自其他类型的、最终产生回复的消费者的),回复将被发送到消息reply-channel标头中的通道;启动请求/回复场景的框架组件(入站网关、消息传递网关、sendAndReceive中的方法MessagingTemplate)会自动设置此标头,因此您无需执行任何操作;它就是有效的。