出站閘道器
以下列表顯示了 AMQP 出站閘道器可能具有的屬性
-
Java DSL
-
Java
-
XML
@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 | 配置的 AMQP 模板的 Bean 引用。可選(預設為 amqpTemplate)。 |
| 4 | 訊息應傳送到的 AMQP 交換機的名稱。如果未提供,訊息將傳送到預設的無名交換機。與“exchange-name-expression”互斥。可選。 |
| 5 | 一個 SpEL 表示式,用於確定訊息應傳送到的 AMQP 交換機的名稱,訊息作為根物件。如果未提供,訊息將傳送到預設的無名交換機。與“exchange-name”互斥。可選。 |
| 6 | 當註冊多個消費者時,此消費者的順序,從而實現負載均衡和故障轉移。可選(預設為 Ordered.LOWEST_PRECEDENCE [=Integer.MAX_VALUE])。 |
| 7 | 接收到來自 AMQP 佇列並轉換後,回覆訊息應傳送到的訊息通道。可選。 |
| 8 | 閘道器在將回復訊息傳送到 reply-channel 時等待的時間。這僅適用於 reply-channel 可能會阻塞的情況——例如,具有容量限制且當前已滿的 QueueChannel。預設為無限。 |
| 9 | 當為 true 時,如果在 AmqpTemplate 的 replyTimeout 屬性指定的時間內未收到回覆訊息,閘道器將丟擲異常。預設為 true。 |
| 10 | 傳送訊息時使用的 routing-key。預設情況下,這是一個空 String。與“routing-key-expression”互斥。可選。 |
| 11 | 一個 SpEL 表示式,用於確定傳送訊息時使用的 routing-key,訊息作為根物件(例如,“payload.key”)。預設情況下,這是一個空 String。與 routing-key 互斥。可選。 |
| 12 | 訊息的預設投遞模式:PERSISTENT 或 NON_PERSISTENT。如果 header-mapper 設定了投遞模式,則會覆蓋此設定。如果 Spring Integration 訊息頭 amqp_deliveryMode 存在,則 DefaultHeaderMapper 會設定該值。如果未提供此屬性且 header mapper 未設定它,則預設值取決於 RabbitTemplate 使用的底層 Spring AMQP MessagePropertiesConverter。如果完全未自定義,則預設值為 PERSISTENT。可選。 |
| 13 | 自 4.2 版本起。一個定義關聯資料的表示式。提供時,這會將底層 AMQP 模板配置為接收發布者確認。需要一個專用的 RabbitTemplate 和一個 CachingConnectionFactory,其 publisherConfirms 屬性設定為 true。當收到釋出者 confirm 並提供了關聯資料時,它將寫入 confirm-ack-channel 或 confirm-nack-channel,具體取決於確認型別。confirm 的有效負載是關聯資料,由該表示式定義。訊息具有一個頭“amqp_publishConfirm”,設定為 true (ack) 或 false (nack)。對於 nack 確認,Spring Integration 提供了一個額外的頭 amqp_publishConfirmNackCause。示例:headers['myCorrelationData'] 和 payload。如果表示式解析為 Message<?> 例項(例如 #this),則在 ack/nack 通道上發出的訊息將基於該訊息,並新增額外的頭。以前,無論型別如何,都會建立一個新訊息,並將關聯資料作為其有效負載。另請參閱 釋出者確認和返回的替代機制。可選。 |
| 14 | 傳送肯定 (ack) 釋出者確認的通道。有效負載是 confirm-correlation-expression 定義的關聯資料。如果表示式是 #root 或 #this,則訊息是根據原始訊息構建的,並將 amqp_publishConfirm 頭設定為 true。另請參閱 釋出者確認和返回的替代機制。可選(預設為 nullChannel)。 |
| 15 | 傳送否定 (nack) 釋出者確認的通道。有效負載是 confirm-correlation-expression 定義的關聯資料(如果未配置 ErrorMessageStrategy)。如果表示式是 #root 或 #this,則訊息是根據原始訊息構建的,並將 amqp_publishConfirm 頭設定為 false。當存在 ErrorMessageStrategy 時,訊息是一個 ErrorMessage,其有效負載為 NackedAmqpMessageException。另請參閱 釋出者確認和返回的替代機制。可選(預設為 nullChannel)。 |
| 16 | 設定後,如果在指定毫秒時間內未收到釋出者確認,閘道器將合成一個否定確認 (nack)。待處理的確認每此值的 50% 檢查一次,因此傳送 nack 的實際時間將在此值的 1 倍到 1.5 倍之間。預設無(不會生成 nack)。 |
| 17 | 返回訊息傳送到的通道。提供時,底層 AMQP 模板被配置為將無法投遞的訊息返回給介面卡。當未配置 ErrorMessageStrategy 時,訊息是根據從 AMQP 接收到的資料構建的,並帶有以下附加頭:amqp_returnReplyCode、amqp_returnReplyText、amqp_returnExchange 和 amqp_returnRoutingKey。當存在 ErrorMessageStrategy 時,訊息是一個 ErrorMessage,其有效負載為 ReturnedAmqpMessageException。另請參閱 釋出者確認和返回的替代機制。可選。 |
| 18 | 對 ErrorMessageStrategy 實現的引用,用於在傳送返回或否定確認的訊息時構建 ErrorMessage 例項。 |
| 19 | 設定為 false 時,端點在應用程式上下文初始化期間嘗試連線到代理。這允許透過在代理關閉時記錄錯誤訊息來“快速失敗”檢測不良配置。當為 true(預設值)時,連線(如果由於其他元件建立而尚未存在)在傳送第一條訊息時建立。 |
|
返回通道
使用 |
底層 AmqpTemplate 的預設 replyTimeout 為五秒。如果需要更長的超時,必須在 template 上進行配置。 |
請注意,出站介面卡和出站閘道器配置之間的唯一區別是 expectReply 屬性的設定。