此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.4.3! |
出站网关
以下清单显示了 AMQP 出站网关的可能属性:
-
Java DSL
-
Java
-
XML
@Bean
public IntegrationFlow amqpOutbound(AmqpTemplate amqpTemplate) {
return f -> f.handle(Amqp.outboundGateway(amqpTemplate)
.routingKey("foo")) // default exchange - route to queue 'foo'
.get();
}
@MessagingGateway(defaultRequestChannel = "amqpOutbound.input")
public interface MyGateway {
String sendToRabbit(String data);
}
@Bean
@ServiceActivator(inputChannel = "amqpOutboundChannel")
public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
outbound.setExpectReply(true);
outbound.setRoutingKey("foo"); // default exchange - route to queue 'foo'
return outbound;
}
@Bean
public MessageChannel amqpOutboundChannel() {
return new DirectChannel();
}
@MessagingGateway(defaultRequestChannel = "amqpOutboundChannel")
public interface MyGateway {
String sendToRabbit(String data);
}
<int-amqp:outbound-gateway id="outboundGateway" (1)
request-channel="myRequestChannel" (2)
amqp-template="" (3)
exchange-name="" (4)
exchange-name-expression="" (5)
order="1" (6)
reply-channel="" (7)
reply-timeout="" (8)
requires-reply="" (9)
routing-key="" (10)
routing-key-expression="" (11)
default-delivery-mode"" (12)
confirm-correlation-expression="" (13)
confirm-ack-channel="" (14)
confirm-nack-channel="" (15)
confirm-timeout="" (16)
return-channel="" (17)
error-message-strategy="" (18)
lazy-connect="true" /> (19)
1 | 此适配器的唯一 ID。 自选。 |
2 | 消息通道,将消息发送到该通道,以便将消息转换并发布到 AMQP 交换。 必填。 |
3 | 对已配置的 AMQP 模板的 Bean 引用。
可选(默认为amqpTemplate ). |
4 | 应将消息发送到的 AMQP 交换的名称。 如果未提供,则消息将发送到默认的 no-name cxchange。 与 'exchange-name-expression' 互斥。 自选。 |
5 | 一个 SPEL 表达式,用于确定应将消息发送到的 AMQP 交换的名称,并将消息作为根对象。 如果未提供,则消息将发送到默认的 no-name 交换。 与 'exchange-name' 互斥。 自选。 |
6 | 注册多个使用者时此使用者的顺序,从而启用负载均衡和故障转移。
可选(默认为Ordered.LOWEST_PRECEDENCE [=Integer.MAX_VALUE] ). |
7 | 从 AMQP 队列接收回复并进行转换后,应将回复发送到的消息通道。 自选。 |
8 | 网关在将回复消息发送到reply-channel .
这仅适用于reply-channel can 阻止 — 例如QueueChannel 容量限制当前已满。
默认为 infinity。 |
9 | 什么时候true ,如果AmqpTemplate’s `replyTimeout 财产。
默认为true . |
10 | 这routing-key 以在发送消息时使用。
默认情况下,这是一个空的String .
与 'routing-key-expression' 互斥。
自选。 |
11 | 一个 SpEL 表达式,用于确定routing-key 在发送消息时使用,将消息作为根对象(例如,'payload.key')。
默认情况下,这是一个空的String .
与 'routing-key' 互斥。
自选。 |
12 | 消息的默认传递模式:PERSISTENT 或NON_PERSISTENT .
如果header-mapper 设置传递模式。
如果 Spring Integration 消息标头amqp_deliveryMode 存在时,DefaultHeaderMapper 设置值。
如果未提供此属性并且 Headers 映射器未设置它,则默认值取决于底层的 Spring AMQPMessagePropertiesConverter 由RabbitTemplate .
如果根本没有自定义,则默认值为PERSISTENT .
自选。 |
13 | 从 4.2 版本开始。
定义关联数据的表达式。
如果提供,这会将底层 AMQP 模板配置为接收发布者确认。
需要专用的RabbitTemplate 以及CachingConnectionFactory 使用publisherConfirms 属性设置为true .
收到发布者确认并提供关联数据后,该数据将写入confirm-ack-channel 或confirm-nack-channel ,具体取决于确认类型。
确认的有效负载是此表达式定义的关联数据。
邮件的标头 'amqp_publishConfirm' 设置为true (ack ) 或false (nack ).
为nack confirmations,则 Spring 集成提供了一个额外的 Headersamqp_publishConfirmNackCause .
例子:headers['myCorrelationData'] 和payload .
如果表达式解析为Message<?> 实例(例如#this )、消息
在ack /nack channel 基于该消息,并添加了其他标头。
以前,无论类型如何,都会使用关联数据作为其负载创建新消息。
另请参阅发布者确认和返回的替代机制。
自选。 |
14 | 正 (ack ) 发布者确认。
有效负载是由confirm-correlation-expression .
如果表达式为#root 或#this ,则消息是从原始消息构建的,其中amqp_publishConfirm header 设置为true .
另请参阅发布者确认和返回的替代机制。
可选(默认值为nullChannel ). |
15 | 负数 (nack ) 发布者确认。
有效负载是由confirm-correlation-expression (如果没有ErrorMessageStrategy configured)。
如果表达式为#root 或#this ,则消息是从原始消息构建的,其中amqp_publishConfirm header 设置为false .
当存在ErrorMessageStrategy ,则消息是一个ErrorMessage 替换为NackedAmqpMessageException 有效载荷。
另请参阅发布者确认和返回的替代机制。
可选(默认值为nullChannel ). |
16 | 设置后,如果在此时间(以毫秒为单位)内未收到发布者确认,网关将合成否定确认 (nack)。 待处理确认每检查一次此值的 50%,因此发送 nack 的实际时间将介于此值的 1 倍到 1.5 倍之间。 默认无(不会生成 nack)。 |
17 | 返回的消息发送到的通道。
如果提供,则底层 AMQP 模板配置为将无法传递的消息返回给适配器。
当没有ErrorMessageStrategy 配置后,该消息是根据从 AMQP 接收的数据构建的,并具有以下附加标头:amqp_returnReplyCode ,amqp_returnReplyText ,amqp_returnExchange 和amqp_returnRoutingKey .
当存在ErrorMessageStrategy ,则消息是一个ErrorMessage 替换为ReturnedAmqpMessageException 有效载荷。
另请参阅发布者确认和返回的替代机制。
自选。 |
18 | 对ErrorMessageStrategy 用于构建的 implementation used to buildErrorMessage 实例。 |
19 | 当设置为false 时,终端节点将尝试在应用程序上下文初始化期间连接到代理。
这允许在代理关闭时通过记录错误消息来“快速失败”检测错误配置。
什么时候true (默认值),则在发送第一条消息时建立连接(如果连接尚不存在,因为其他组件建立了连接)。 |
return-channel (返回通道)
使用 |
底层AmqpTemplate 具有默认的replyTimeout 的 5 秒。
如果需要更长的超时时间,则必须在template . |
请注意,出站适配器和出站网关配置之间的唯一区别是expectReply
财产。