此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1! |
出站通道适配器
以下示例显示了 AMQP 出站通道适配器的可用属性:
-
Java DSL
-
Java
-
XML
@Bean
public IntegrationFlow amqpOutbound(AmqpTemplate amqpTemplate,
MessageChannel amqpOutboundChannel) {
return IntegrationFlow.from(amqpOutboundChannel)
.handle(Amqp.outboundAdapter(amqpTemplate)
.routingKey("queue1")) // default exchange - route to queue 'queue1'
.get();
}
@Bean
@ServiceActivator(inputChannel = "amqpOutboundChannel")
public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
outbound.setRoutingKey("queue1"); // default exchange - route to queue 'queue1'
return outbound;
}
@Bean
public MessageChannel amqpOutboundChannel() {
return new DirectChannel();
}
<int-amqp:outbound-channel-adapter id="outboundAmqp" (1)
channel="outboundChannel" (2)
amqp-template="myAmqpTemplate" (3)
exchange-name="" (4)
exchange-name-expression="" (5)
order="1" (6)
routing-key="" (7)
routing-key-expression="" (8)
default-delivery-mode"" (9)
confirm-correlation-expression="" (10)
confirm-ack-channel="" (11)
confirm-nack-channel="" (12)
confirm-timeout="" (13)
wait-for-confirm="" (14)
return-channel="" (15)
error-message-strategy="" (16)
header-mapper="" (17)
mapped-request-headers="" (18)
lazy-connect="true" (19)
multi-send="false"/> (20)
1 | 此适配器的唯一 ID。 自选。 |
2 | 消息通道,消息应发送到该通道,以便将其转换并发布到 AMQP 交换。 必填。 |
3 | Bean 对已配置的 AMQP 模板的引用。
可选(默认为amqpTemplate ). |
4 | 将消息发送到的 AMQP 交换的名称。 如果未提供,则消息将发送到默认的无名交换。 与“exchange-name-expression”互斥。 自选。 |
5 | 一种 SpEL 表达式,用于确定将消息发送到的 AMQP 交换的名称,并将消息作为根对象。 如果未提供,则消息将发送到默认的无名交换。 与“交易所名称”互斥。 自选。 |
6 | 注册多个使用者时此使用者的顺序,从而启用负载平衡和故障转移。
可选(默认为Ordered.LOWEST_PRECEDENCE [=Integer.MAX_VALUE] ). |
7 | 发送消息时使用的固定路由键。
默认情况下,这是一个空的String .
与 'routing-key-expression' 互斥。
自选。 |
8 | 一个 SpEL 表达式,用于确定发送消息时要使用的路由键,将消息作为根对象(例如,'payload.key')。
默认情况下,这是一个空的String .
与“路由键”互斥。
自选。 |
9 | 消息的默认传递模式:PERSISTENT 或NON_PERSISTENT .
如果header-mapper 设置投放模式。
如果 Spring Integration 消息头amqp_deliveryMode 存在,则DefaultHeaderMapper 设置值。
如果未提供此属性并且标头映射器未设置它,则默认值取决于底层 Spring AMQPMessagePropertiesConverter 由RabbitTemplate .
如果根本不自定义,则默认值为PERSISTENT .
自选。 |
10 | 定义相关数据的表达式。
提供后,这会将基础 AMQP 模板配置为接收发布者确认。
需要专用的RabbitTemplate 和CachingConnectionFactory 使用publisherConfirms 属性设置为true .
收到发布者确认并提供相关数据时,它将写入confirm-ack-channel 或confirm-nack-channel ,具体取决于确认类型。
确认的有效负载是相关数据,如此表达式所定义。
邮件的“amqp_publishConfirm”标头设置为true (ack ) 或false (nack ).
例子:headers['myCorrelationData'] 和payload .
4.1 版引入了amqp_publishConfirmNackCause 消息头。
它包含cause 出版商确认的“nack”。
从 4.2 版开始,如果表达式解析为Message<?> 实例(例如#this ),则在ack /nack channel 基于该消息,并添加了其他标头。
以前,无论类型如何,都会使用相关数据作为有效负载创建新消息。
另请参阅发布者确认和返回的替代机制。
自选。 |
11 | 正 (ack ) 发布者确认已发送。
有效负载是由confirm-correlation-expression .
如果表达式是#root 或#this ,则消息是从原始消息构建的,使用amqp_publishConfirm header 设置为true .
另请参阅发布者确认和返回的替代机制。
可选(默认值为nullChannel ). |
12 | 负 (nack ) 发布者确认。
有效负载是由confirm-correlation-expression (如果没有ErrorMessageStrategy 已配置)。
如果表达式是#root 或#this ,则消息是从原始消息构建的,使用amqp_publishConfirm header 设置为false .
当有ErrorMessageStrategy ,则消息是ErrorMessage 使用NackedAmqpMessageException 有效载荷。
另请参阅发布者确认和返回的替代机制。
可选(默认值为nullChannel ). |
13 | 设置后,如果在此时间内未收到发布者确认(毫秒),适配器将合成否定确认 (nack)。 每 50% 检查一次待处理的确认,因此发送 nack 的实际时间将介于该值的 1 倍到 1.5 倍之间。 另请参阅发布者确认和返回的替代机制。 默认为无(不会生成 nacks)。 |
14 | 当设置为 true 时,调用线程将阻塞,等待发布者确认。
这需要一个RabbitTemplate 配置为 confirms 以及confirm-correlation-expression .
线程将阻塞最多confirm-timeout (或默认为 5 秒)。
如果发生超时,则MessageTimeoutException 将被扔出。
如果启用了返回并返回了一条消息,或者在等待确认时发生任何其他异常,则MessageHandlingException 将被抛出,并带有适当的消息。 |
15 | 将返回的消息发送到的通道。
提供后,基础 AMQP 模板配置为将无法传递的消息返回到适配器。
当没有ErrorMessageStrategy 配置后,消息是根据从 AMQP 接收的数据构造的,并带有以下附加标头:amqp_returnReplyCode ,amqp_returnReplyText ,amqp_returnExchange ,amqp_returnRoutingKey .
当有ErrorMessageStrategy ,则消息是ErrorMessage 使用ReturnedAmqpMessageException 有效载荷。
另请参阅发布者确认和返回的替代机制。
自选。 |
16 | 对ErrorMessageStrategy 用于构建的实现ErrorMessage 发送返回或否定确认消息时的实例。 |
17 | 对AmqpHeaderMapper 在发送 AMQP 消息时使用。
默认情况下,只有标准 AMQP 属性(例如contentType )被复制到 Spring IntegrationMessageHeaders .
默认的“DefaultAmqpHeaderMapper”不会将任何用户定义的标头复制到消息中。
如果提供了“request-header-names”,则不允许。
自选。 |
18 | 要从MessageHeaders 到 AMQP 消息。
如果提供了“header-mapper”引用,则不允许。
此列表中的值也可以是与标头名称匹配的简单模式(例如 或"*" "thing1*, thing2" 或"*thing1" ). |
19 | 当设置为false ,则端点在应用程序上下文初始化期间尝试连接到代理。
这允许“快速失败”检测错误配置,但如果代理关闭,也会导致初始化失败。
什么时候true (默认值),则在发送第一条消息时建立连接(如果连接尚不存在,因为其他组件建立了连接)。 |
20 | 当设置为true 、有效负载类型Iterable<Message<?>> 将作为离散消息发送到单个范围内的同一通道上RabbitTemplate 调用。
需要一个RabbitTemplate .
什么时候wait-for-confirms 是真的,RabbitTemplate.waitForConfirmsOrDie() 在发送消息后调用。
使用事务模板时,发送将在新事务或已启动的事务(如果存在)中执行。 |
返回通道
使用 |