輸出閘道
以下列表顯示 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 。預設情況下,這是一個空字串。與 'routing-key-expression' 互斥。選填。 |
11 | SpEL 表達式,評估以決定傳送訊息時要使用的 routing-key ,訊息作為根物件(例如,'payload.key')。預設情況下,這是一個空字串。與 'routing-key' 互斥。選填。 |
12 | 訊息的預設傳遞模式:PERSISTENT 或 NON_PERSISTENT 。若 header-mapper 設定了傳遞模式,則會覆寫。若 Spring Integration 訊息標頭 amqp_deliveryMode 存在,則 DefaultHeaderMapper 會設定該值。若未提供此屬性且標頭對應器未設定,則預設值取決於 RabbitTemplate 使用的基礎 Spring AMQP MessagePropertiesConverter 。若完全未自訂,則預設值為 PERSISTENT 。選填。 |
13 | 自版本 4.2 起。定義關聯資料的表達式。若提供,這會設定基礎 AMQP 範本以接收發布者確認。需要專用的 RabbitTemplate 和 CachingConnectionFactory ,且 publisherConfirms 屬性設定為 true 。當收到發布者確認並提供關聯資料時,會根據確認類型寫入 confirm-ack-channel 或 confirm-nack-channel 。確認的酬載是關聯資料,如本表達式所定義。訊息具有標頭 '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 時,端點會在應用程式上下文初始化期間嘗試連線到 Broker。這允許透過在 Broker 關閉時記錄錯誤訊息來「快速失敗」偵測錯誤設定。當為 true (預設值)時,連線會在傳送第一則訊息時建立(如果連線尚不存在,因為其他元件已建立連線)。 |
回傳通道
使用 |
基礎 AmqpTemplate 的預設 replyTimeout 為五秒。若您需要更長的逾時時間,則必須在範本上設定。 |
請注意,輸出配接器和輸出閘道設定之間的唯一區別在於 expectReply
屬性的設定。