Overview

路由器是许多消息架构中的关键元素。它们从消息通道中使用消息,根据一组条件将每个使用过的消息转发到一个或更多不同的消息通道。

Spring Integration 提供以下路由器:

路由器实现共享许多配置参数。但是,路由器之间存在某些差异。此外,配置参数的可用性取决于路由器是在链内还是链外使用。为了提供快速概述,所有可用的属性都列在以下两个表中。

下表显示了用于链外路由器的配置参数:

Table 1. Routers Outside a Chain
Attribute router header value router xpath router payload type router recipient list route exception type router

apply-sequence

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

default-output-channel

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

resolution-required

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

ignore-send-failures

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

timeout

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

id

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

auto-startup

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

input-channel

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

order

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

method

image::tickmark.png[]

ref

image::tickmark.png[]

expression

image::tickmark.png[]

header-name

image::tickmark.png[]

evaluate-as-string

image::tickmark.png[]

xpath-expression-ref

image::tickmark.png[]

converter

image::tickmark.png[]

下表显示了用于链内路由器的配置参数:

Table 2. Routers Inside a Chain
Attribute router header value router xpath router payload type router recipient list router exception type router

apply-sequence

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

default-output-channel

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

resolution-required

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

ignore-send-failures

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

timeout

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

image::tickmark.png[]

id

auto-startup

input-channel

order

method

image::tickmark.png[]

ref

image::tickmark.png[]

expression

image::tickmark.png[]

header-name

image::tickmark.png[]

evaluate-as-string

image::tickmark.png[]

xpath-expression-ref

image::tickmark.png[]

converter

image::tickmark.png[]

自 Spring Integration 2.1 起,路由器参数已在所有路由器实现中进行了更标准化的处理。因此,一些细微的更改可能会破坏基于旧版 Spring Integration 的应用程序。 自 Spring Integration 2.1 起,ignore-channel-name-resolution-failures 属性已被弃用,有利于将其行为与 resolution-required 属性合并。同时,resolution-required 属性现在默认为 true。 在进行这些更改之前,resolution-required 属性默认为 false,这会导致在未解析出任何信道并且未设置 default-output-channel 时,消息被静默丢弃。新行为需要至少有一个已解析的信道,并且默认情况下,如果未确定信道(或发送尝试不成功),将抛出 MessageDeliveryException。 如果你确实想静默丢弃消息,可以设置 default-output-channel="nullChannel"