对于最新稳定版本,请使用 Spring Integration 7.0.0spring-doc.cadn.net.cn

入站网关

入站网关支持入站信道适配器上的所有属性(除了“通道”被“请求通道”替换),以及一些额外的属性。 以下列表展示了可用的属性: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属性(例如:内容类型)被复制到Spring Integration之间消息头. AMQP 内任何用户自定义的头部消息属性默认情况下,不会复制到或复制 AMQP 消息DefaultAmqpHeaderMapper. 如果提供了“request-header-names”或“reply-header-names”,则不允许。
4 AMQP头部名称的逗号分隔列表,从AMQP请求映射到以下消息头. 只有在未提供“头部映射器”引用时,才能提供该属性。 该列表中的值也可以是简单的模式,用于与头部名称匹配(例如: 或"*"“东西1*,东西2”“*东西1”).
5 逗号分隔的姓名列表消息头映射到AMQP回复消息的AMQP消息属性中。 所有标准头部(例如内容类型)映射到AMQP消息属性,而用户自定义的头映射到“头”属性。 只有在未提供“头部映射器”引用时,才能提供该属性。 该列表中的值也可以是简单的模式,用于与头部名称匹配(例如,或"*"“福*,酒吧”“*福”).
6 消息通道,期望回复消息。 自选。
7 收到超时关于标的o.s.i.core.消息模板用于接收来自回复频道的消息。 如果未指定,该性质默认为1000(1秒) 只有当容器线程在回复发送前交接给另一个线程时才适用。
8 定制化Amqp模板BEAN 引用(以便更好地控制回复消息的发送)。 你可以提供另一种实现兔子模板.
9 回复 o.s.amqp.core.地址请求消息没有回复财产。 如果没有指定这个选项,则不行AMQP-模板提供时,不回复请求消息中存在属性,且 一非法州例外是因为回复无法路由而被抛出。 如果未指定该选项且外部AMQP-模板提供例外,不予提出例外。 你必须选择这个选项,或者配置默认设置交换路由键基于那个模板, 如果你预期情况不行回复请求消息中存在属性。

请参见入站信道适配器中关于配置监听器容器属性。spring-doc.cadn.net.cn

从5.5版本开始,Amqp入站通道适配器可以配置为org.springframework.amqp.rabbit.retry.MessageRecoverer该策略用于恢复回调当重试作在内部被调用时。 看setMessageRecoveryer()更多信息请参见JavaDocs。spring-doc.cadn.net.cn

批量消息