此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1spring-doc.cadn.net.cn

出站网关

以下列表显示了 AMQP 出站网关的可能属性:spring-doc.cadn.net.cn

@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 Bean 对已配置的 AMQP 模板的引用。 可选(默认为amqpTemplate).
4 应将消息发送到的 AMQP 交换的名称。 如果未提供,则消息将发送到默认的无名 cxchange。 与“exchange-name-expression”互斥。 自选。
5 一个 SpEL 表达式,用于确定应将消息发送到的 AMQP 交换的名称,并将消息作为根对象。 如果未提供,则消息将发送到默认的无名交换。 与“交易所名称”互斥。 自选。
6 注册多个使用者时此使用者的顺序,从而启用负载平衡和故障转移。 可选(默认为Ordered.LOWEST_PRECEDENCE [=Integer.MAX_VALUE]).
7 从 AMQP 队列接收并转换后应将回复发送到的消息通道。 自选。
8 网关在将回复消息发送到reply-channel. 这仅适用于reply-channel可以阻止 — 例如QueueChannel当前容量限制已满。 默认为无穷大。
9 什么时候true,如果网关在AmqpTemplate’s `replyTimeout财产。 默认为true.
10 routing-key在发送消息时使用。 默认情况下,这是一个空的String. 与 'routing-key-expression' 互斥。 自选。
11 评估 SpEL 表达式以确定routing-key在发送消息时使用,将消息作为根对象(例如,“payload.key”)。 默认情况下,这是一个空的String. 与“路由键”互斥。 自选。
12 消息的默认传递模式:PERSISTENTNON_PERSISTENT. 如果header-mapper设置投放模式。 如果 Spring Integration 消息头amqp_deliveryMode存在,则DefaultHeaderMapper设置值。 如果未提供此属性并且标头映射器未设置它,则默认值取决于底层 Spring AMQPMessagePropertiesConverterRabbitTemplate. 如果根本不自定义,则默认值为PERSISTENT. 自选。
13 从 4.2 版本开始。 定义相关数据的表达式。 提供后,这会将基础 AMQP 模板配置为接收发布者确认。 需要专用的RabbitTemplateCachingConnectionFactory使用publisherConfirms属性设置为true. 收到发布者确认并提供相关数据时,它将写入confirm-ack-channelconfirm-nack-channel,具体取决于确认类型。 确认的有效负载是相关数据,如此表达式所定义。 邮件的标头“amqp_publishConfirm”设置为true (ack) 或false (nack). 为nackconfirmations,Spring Integration 提供了一个额外的标头amqp_publishConfirmNackCause. 例子:headers['myCorrelationData']payload. 如果表达式解析为Message<?>实例(例如#this),消息 在ack/nackchannel 基于该消息,并添加了其他标头。 以前,无论类型如何,都会使用相关数据作为有效负载创建新消息。 另请参阅发布者确认和返回的替代机制。 自选。
14 正 (ack) 发布者确认。 有效负载是由confirm-correlation-expression. 如果表达式是#root#this,则消息是从原始消息构建的,使用amqp_publishConfirmheader 设置为true. 另请参阅发布者确认和返回的替代机制。 可选(默认值为nullChannel).
15 负 (nack) 发布者确认。 有效负载是由confirm-correlation-expression(如果没有ErrorMessageStrategy已配置)。 如果表达式是#root#this,则消息是从原始消息构建的,使用amqp_publishConfirmheader 设置为false. 当有ErrorMessageStrategy,则消息是ErrorMessage使用NackedAmqpMessageException有效载荷。 另请参阅发布者确认和返回的替代机制。 可选(默认值为nullChannel).
16 设置后,如果在此时间内未收到发布者确认,网关将合成否定确认 (nack)(以毫秒为单位)。 每 50% 检查一次待处理的确认,因此发送 nack 的实际时间将介于该值的 1 倍到 1.5 倍之间。 默认为无(不会生成 nacks)。
17 将返回的消息发送到的通道。 提供后,基础 AMQP 模板配置为将无法传递的消息返回到适配器。 当没有ErrorMessageStrategy配置后,消息是根据从 AMQP 接收的数据构造的,并带有以下附加标头:amqp_returnReplyCode,amqp_returnReplyText,amqp_returnExchangeamqp_returnRoutingKey. 当有ErrorMessageStrategy,则消息是ErrorMessage使用ReturnedAmqpMessageException有效载荷。 另请参阅发布者确认和返回的替代机制。 自选。
18 ErrorMessageStrategy用于构建的实现ErrorMessage发送返回或否定确认消息时的实例。
19 当设置为false,则端点在应用程序上下文初始化期间尝试连接到代理。 这允许在代理关闭时通过记录错误消息来“快速失败”检测错误配置。 什么时候true(默认值),则在发送第一条消息时建立连接(如果连接尚不存在,因为其他组件建立了连接)。
返回通道

使用return-channel需要一个RabbitTemplate使用mandatory属性设置为trueCachingConnectionFactory使用publisherReturns属性设置为true. 当使用多个具有返回的出站端点时,单独的RabbitTemplate每个端点都需要。spring-doc.cadn.net.cn

基础AmqpTemplate具有默认值replyTimeout五秒钟。 如果需要更长的超时,则必须在template.

请注意,出站适配器和出站网关配置之间的唯一区别是expectReply财产。spring-doc.cadn.net.cn