入站网关

入站网关支持入站通道适配器上的所有属性(除了 channelrequest-channel 替换),以及一些附加属性。以下列表显示了可用属性:

  • Java DSL

  • Java

  • XML

@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 接收 AMQP 消息时使用的 AmqpHeaderMapper 的引用。可选。默认情况下,只有标准的 AMQP 属性(如 contentType)在 Spring Integration MessageHeaders 之间复制。默认的 DefaultAmqpHeaderMapper 不会将 AMQP MessageProperties 中的任何用户定义头复制到或从 AMQP 消息。如果提供了 'request-header-names' 或 'reply-header-names',则不允许使用此属性。
4 逗号分隔的 AMQP 头名称列表,用于将 AMQP 请求中的头映射到 MessageHeaders。只有在未提供 'header-mapper' 引用时才能提供此属性。此列表中的值也可以是与头名称匹配的简单模式(例如 "*""thing1*, thing2""*thing1")。
5 逗号分隔的 MessageHeaders 名称列表,用于将头映射到 AMQP 回复消息的 AMQP 消息属性中。所有标准头(如 contentType)都映射到 AMQP 消息属性,而用户定义的头则映射到 'headers' 属性。只有在未提供 'header-mapper' 引用时才能提供此属性。此列表中的值也可以是与头名称匹配的简单模式(例如 "*""foo*, bar""*foo")。
6 预期回复消息的消息通道。可选。
7 设置用于从回复通道接收消息的基础 o.s.i.core.MessagingTemplatereceiveTimeout。如果未指定,此属性默认为 1000(1 秒)。仅当容器线程在发送回复之前切换到另一个线程时适用。
8 自定义的 AmqpTemplate bean 引用(用于对要发送的回复消息进行更多控制)。您可以提供 RabbitTemplate 的替代实现。
9 requestMessage 没有 replyTo 属性时,要使用的 replyTo o.s.amqp.core.Address。如果未指定此选项,未提供 amqp-template,请求消息中不存在 replyTo 属性,则会抛出 IllegalStateException,因为无法路由回复。如果未指定此选项并提供了外部 amqp-template,则不会抛出异常。如果您预期在请求消息中不存在 replyTo 属性的情况,则必须指定此选项或在该模板上配置默认的 exchangeroutingKey

请参阅 入站通道适配器 中关于配置 listener-container 属性的说明。

从 5.5 版开始,AmqpInboundChannelAdapter 可以配置 org.springframework.amqp.rabbit.retry.MessageRecoverer 策略,该策略在内部调用重试操作时在 RecoveryCallback 中使用。有关更多信息,请参阅 setMessageRecoverer() JavaDocs。

批量消息

请参阅 批量消息

© . This site is unofficial and not affiliated with VMware.