@Router in Spring Integration with annotations (request/reply)

ぐ巨炮叔叔 提交于 2020-01-15 04:00:23

问题


Could you provide any example for routing messages in Spring Integration?. Filter by payload message, header or something like the following:

<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>

How the response works? I mean, if I send:

channel -> router -> transformer -> gateway

Simple but I am looking something similar to this example:

<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>

When my gateway receives a message and sends the response to reply channel. How can I inform in my router what is the correct reply channel?


回答1:


@Router methods simply return the channel(s) or channel name(s) to which the message will be routed.

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

For your second question, you need to show more of your flow; what is "upstream" of channel?

You can omit the reply-channel from the gateway (or omit the output-channel from other types of, ultimate reply-producing consumer) and the reply will be sent to the channel that's in the message's reply-channel header; framework components that start request/reply scenarios (inbound gateways, messaging gateways, sendAndReceive methods in the MessagingTemplate) set up this header automatically so there's nothing for you to do; it just works.



来源:https://stackoverflow.com/questions/27481337/router-in-spring-integration-with-annotations-request-reply

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!