本文介绍了@Router在Spring集成的注解(请求/应答)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能提供的Spring集成路由信息的例子?通过有效载荷的消息,标题或类似如下过滤器:

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?

推荐答案

@Router 方法简单地返回通道(S)或通道名称(S),该​​消息将被路由。

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

您可以省略回复通道从网关(或省略输出通道与其他类型的,最终的回复生产消费),并答复将被发送到这是在消息的回复通道头通道;该开始请求框架组件/答复的情况(入站网关,短信网关, sendAndReceive MessagingTemplate 方法)设置此自动头球所以没有什么给你做;它只是工作。

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.

这篇关于@Router在Spring集成的注解(请求/应答)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 13:32
查看更多