2013-04-03 39 views
1

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

为什么?

回答

1

我很努力地看到@Async可以在这里的任何地方工作,因为出发点是当您的代码调用ProductPricingGateway.broadcastPricing()方法时。

对于gw上的@Async,调度程序会发送什么?

同样,如果服务上有@Async,那么调度程序通过identifiers会怎样?

正确的方法是尽快去异步是使product.pricing.outbound.requests一个ExecutorChannel ...

http://static.springsource.org/spring-integration/reference/html/messaging-channels-section.html#executor-channel

http://static.springsource.org/spring-integration/reference/html/messaging-channels-section.html#channel-configuration-executorchannel

...其中调用线程的手离开消息任务执行者。

相关问题