我有一个远程服务,我打电话来为特定事件发生时加载产品的定价数据。一旦加载,产品定价将被广播给其他消费者在其他地方处理。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
方法(这看起来更合适的地方)声明它,聚合器永远不会被调用。
为什么?