入站网关

入站网关支持入站通道适配器上的所有属性(除了 'channel' 被 'request-channel' 替换),以及一些其他属性。 以下清单显示了可用的属性:spring-doc.cadn.net.cn

@Bean // return the upper-cased payload
public IntegrationFlow amqpInboundGateway(ConnectionFactory connectionFactory) {
    return IntegrationFlow.from(Amqp.inboundGateway(connectionFactory, "foo"))
            .transform(String.class, String::toUpperCase)
            .get();
}
@Bean
public MessageChannel amqpInputChannel() {
    return new DirectChannel();
}

@Bean
public AmqpInboundGateway inbound(SimpleMessageListenerContainer listenerContainer,
        @Qualifier("amqpInputChannel") MessageChannel channel) {
    AmqpInboundGateway gateway = new AmqpInboundGateway(listenerContainer);
    gateway.setRequestChannel(channel);
    gateway.setDefaultReplyTo("bar");
    return gateway;
}

@Bean
public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) {
    SimpleMessageListenerContainer container =
                    new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames("foo");
    container.setConcurrentConsumers(2);
    // ...
    return container;
}

@Bean
@ServiceActivator(inputChannel = "amqpInputChannel")
public MessageHandler handler() {
    return new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return "reply to " + requestMessage.getPayload();
        }

    };
}
<int-amqp:inbound-gateway
                          id="inboundGateway"                (1)
                          request-channel="myRequestChannel" (2)
                          header-mapper=""                   (3)
                          mapped-request-headers=""          (4)
                          mapped-reply-headers=""            (5)
                          reply-channel="myReplyChannel"     (6)
                          reply-timeout="1000"               (7)
                          amqp-template=""                   (8)
                          default-reply-to="" />             (9)
1 此适配器的唯一 ID。 自选。
2 将转换后的消息发送到的消息通道。 必填。
3 AmqpHeaderMapper在接收 AMQP 消息时使用。 自选。 默认情况下,只有标准的 AMQP 属性(例如contentType) 复制到 Spring 集成或从 Spring 集成复制MessageHeaders. AMQP 中的任何用户定义的标头MessageProperties默认情况下,不会复制到 AMQP 消息或从 AMQP 消息复制DefaultAmqpHeaderMapper. 如果提供了 'request-header-names' 或 'reply-header-names',则不允许。
4 要从 AMQP 请求映射到MessageHeaders. 仅当未提供 'header-mapper' 引用时,才能提供此属性。 此列表中的值也可以是与 Headers 名称匹配的简单模式(例如 或"*""thing1*, thing2""*thing1").
5 以逗号分隔的名称列表MessageHeaders映射到 AMQP 回复消息的 AMQP 消息属性中。 所有标准标头(例如contentType) 映射到 AMQP 消息属性,而用户定义的标头映射到 'headers' 属性。 只有在未提供 'header-mapper' 引用时才能提供此属性。 此列表中的值也可以是要与标头名称匹配的简单模式(例如,或"*""foo*, bar""*foo").
6 需要回复 Messages 的消息通道。 自选。
7 设置receiveTimeout在底层o.s.i.core.MessagingTemplate用于接收来自 Reply Channel 的消息。 如果未指定,则此属性默认为1000(1 秒)。 仅当容器线程在发送回复之前移交给另一个线程时适用。
8 定制的AmqpTemplateBean 引用(以便更好地控制要发送的回复消息)。 您可以提供RabbitTemplate.
9 replyTo o.s.amqp.core.AddressrequestMessage没有replyTo财产。 如果未指定此选项,则为 noamqp-template,则没有replyTo属性存在于请求消息中,并且 一IllegalStateException被抛出,因为无法路由回复。 如果未指定此选项,并且外部amqp-template时,不会引发异常。 您必须指定此选项或配置默认值exchangeroutingKey在该模板上, 如果您预见到没有replyTo属性。

请参阅 Inbound Channel Adapter 中有关配置listener-container属性。spring-doc.cadn.net.cn

从版本 5.5 开始,AmqpInboundChannelAdapter可以配置org.springframework.amqp.rabbit.retry.MessageRecoverer策略,该策略用于RecoveryCallback当内部调用 retry作时。 看setMessageRecoverer()JavaDocs 了解更多信息。spring-doc.cadn.net.cn