入站閘道器

入站閘道器支援入站通道介面卡上的所有屬性(除了 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.