我有一個遠程服務,我打電話來爲特定事件發生時加載產品的定價數據。一旦加載,產品定價將被廣播給其他消費者在其他地方處理。Spring Integration + @Aysnc - Gateway vs ServiceActivator
調用代碼並不關心響應 - 它是一個即忘即會,響應應用程序事件並觸發新的工作流。
爲了儘可能快地保持調用代碼,我想在這裏使用@Async,但我有混合的結果。
的基本流程是:
CallingCode -> ProductPricingGateway -> Aggregator -> BatchedFetchPricingTask
這裏的異步設置:
<task:annotation-driven executor="executor" scheduler="scheduler"/>
<task:scheduler id="scheduler" pool-size="1" />
<task:executor id="executor" keep-alive="30" pool-size="10-20" queue-capacity="500" rejection-policy="CALLER_RUNS" />
使用的其它兩個分量是一個@Gateway
,其intiating碼的呼叫,和一個下游@ServiceActivator
,位於聚合器後面。 (呼叫分成小組)。
public interface ProductPricingGateway {
@Gateway(requestChannel="product.pricing.outbound.requests")
public void broadcastPricing(ProductIdentifer productIdentifier);
}
// ...elsewhere...
@Component
public class BatchedFetchPricingTask {
@ServiceActivator(inputChannel="product.pricing.outbound.requests.batch")
public void fetchPricing(List<ProductIdentifer> identifiers)
{
// omitted
}
}
而其他相關intergation配置:
<int:gateway service-interface="ProductPricingGateway"
default-request-channel="product.pricing.outbound.requests" />
<int:channel id="product.pricing.outbound.requests" />
<int:channel id="product.pricing.outbound.requests.batch" />
我發現,如果我在@ServiceActivator
方法聲明@Async
,它工作正常。 但是,如果我在@Gateway
方法(這看起來更合適的地方)聲明它,聚合器永遠不會被調用。
爲什麼?