為端點新增行為

在 Spring Integration 2.2 之前,您可以透過向輪詢器的 <advice-chain/> 元素新增 AOP 建議來向整個整合流新增行為。但是,假設您只想重試(例如)一個 REST Web 服務呼叫,而不重試任何下游端點。

例如,考慮以下流程

inbound-adapter->poller->http-gateway1->http-gateway2->jdbc-outbound-adapter

如果您在輪詢器的建議鏈中配置了一些重試邏輯,並且由於網路故障導致對 http-gateway2 的呼叫失敗,則重試將導致 http-gateway1http-gateway2 都被第二次呼叫。類似地,在 jdbc-outbound-adapter 中發生瞬時故障後,兩個 HTTP 閘道器都會被第二次呼叫,然後再次呼叫 jdbc-outbound-adapter

Spring Integration 2.2 增加了向單個端點新增行為的能力。這透過向許多端點新增 <request-handler-advice-chain/> 元素來實現。以下示例展示瞭如何在 outbound-gateway 中使用 <request-handler-advice-chain/> 元素

<int-http:outbound-gateway id="withAdvice"
    url-expression="'https:///test1'"
    request-channel="requests"
    reply-channel="nextChannel">
    <int-http:request-handler-advice-chain>
        <ref bean="myRetryAdvice" />
    </int-http:request-handler-advice-chain>
</int-http:outbound-gateway>

在這種情況下,myRetryAdvice 僅本地應用於此閘道器,並且在回覆傳送到 nextChannel 之後不適用於下游採取的進一步操作。建議的範圍僅限於端點本身。

目前,您無法建議整個端點 <chain/>。模式不允許 <request-handler-advice-chain> 作為鏈本身的子元素。

但是,可以將 <request-handler-advice-chain> 新增到 <chain> 元素中的單個生成回覆的端點。一個例外是,在不生成回覆的鏈中,因為鏈中的最後一個元素是 outbound-channel-adapter,所以該最後一個元素無法被建議。如果您需要建議此類元素,則必須將其移出鏈(鏈的 output-channel 成為介面卡的 input-channel)。然後可以像往常一樣建議該介面卡。對於生成回覆的鏈,每個子元素都可以被建議。

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