Common Router Parameters
本节描述了所有路由器参数通用的参数(即本章前面显示的两个表格中全部选中框的参数)。
Inside and Outside a Chain
以下参数对链路内外的所有路由器有效。
apply-sequence
-
This attribute specifies whether sequence number and size headers should be added to each message. This optional attribute defaults to
false
. default-output-channel
-
If set, this attribute provides a reference to the channel where messages should be sent if channel resolution fails to return any channels. If no default output channel is provided, the router throws an exception. If you would like to silently drop those messages instead, set the default output channel attribute value to
nullChannel
.从 6.0 版本开始,设置默认输出通道也会将
channelKeyFallback
选项重置为false
。因此,不会尝试从其名称解析通道,但会退回到此默认输出通道 - 类似于 Javaswitch
语句。如果channelKeyFallback
显式设置为true
,进一步的逻辑将取决于resolutionRequired
选项:仅当resolutionRequired
为false
时,该消息才能从键到未解析通道到达defaultOutputChannel
。因此,AbstractMappingMessageRouter
初始化阶段会拒绝提供defaultOutputChannel
并且将channelKeyFallback
和resolutionRequired
都设置为true
的配置。 resolution-required
-
This attribute specifies whether channel names must always be successfully resolved to channel instances that exist. If set to
true
, aMessagingException
is raised when the channel cannot be resolved. Setting this attribute tofalse
causes any unresolvable channels to be ignored. This optional attribute defaults totrue
.仅当指定了
resolution-required
为false
且未解析通道时,才会向default-output-channel
发送消息。 ignore-send-failures
-
If set to
true
, failures to send to a message channel is ignored. If set tofalse
, aMessageDeliveryException
is thrown instead, and, if the router resolves more than one channel, any subsequent channels do not receive the message.此属性的确切行为取决于发送消息到的
Channel
的类型。例如,当使用直接通道(单线程)时,组件抛出的异常可能会导致发送失败。但是,当将消息发送到简单队列通道(异步)时,抛出异常的可能性比较小。
虽然大多数路由器会路由到一个通道,但它们可以返回多个通道名称。例如, |
此属性默认为 false
。
timeout
-
The
timeout
attribute specifies the maximum amount of time in milliseconds to wait when sending messages to the target Message Channels.
Top-Level (Outside a Chain)
以下参数仅对链路外部的所有顶级路由器有效。
id
-
Identifies the underlying Spring bean definition, which, in the case of routers, is an instance of
EventDrivenConsumer
orPollingConsumer
, depending on whether the router’sinput-channel
is aSubscribableChannel
or aPollableChannel
, respectively. This is an optional attribute. auto-startup
-
This “lifecycle” attribute signaled whether this component should be started during startup of the application context. This optional attribute defaults to
true
. input-channel
-
The receiving message channel of this endpoint.
order
-
This attribute defines the order for invocation when this endpoint is connected as a subscriber to a channel. This is particularly relevant when that channel uses a failover dispatching strategy. It has no effect when this endpoint itself is a polling consumer for a channel with a queue.