来自recipient-list-router的异步调用

时间:2013-07-01 15:33:10

标签: spring spring-integration

我是SI的新手,但现在已经阅读了很多。我必须再从流程中再打一次,这已经实现了。我需要这个调用是非阻塞的,所以链不等待它的执行 - 它被发送到另一个可能已关闭的系统。

我需要向2个频道发送消息,所以我使用了recip-list-router而没有任何条件。

<int:recipient-list-router id="processEngineRouter" input-channel="newApplicationChannel">
    <int:recipient channel="finishFlowChannel"/>
    <int:recipient channel="processEngineChannel"/>
</int:recipient-list-router>

finishFlowChannel完成后,调用processEngineChannel。这很好,但问题是输入newApplicationChannel确实等待processEngineChannel完成,即使我使用Executor通道也应该是异步的。

<int:channel id="finishFlowChannel"/>
<int:chain input-channel="finishFlowChannel" output-channel="apiReplyChannel">
    <!-- create response -->
    <int:transformer ref="xxToYYTransformer"/>
</int:chain>

<int:channel id="processEngineChannel">
    <int:dispatcher task-executor="taskExecutor"/>
</int:channel>
<int:chain input-channel="processEngineChannel">

    <!-- transform x to y -->
    <int:transformer ref="xToYTransformer"/>

    <!-- call PE -->
    <int:gateway request-channel="peRCh"/>
</int:chain>

<task:executor id="taskExecutor"/> task前缀来自http://www.springframework.org/schema/task/spring-task.xsd版本3.1,没有其他设置。

路由器的输入通道是

<int:channel id="newApplicationChannel"/>
<int:channel id="naRequestChannel"/>
<int:chain input-channel="naRequestChannel" output-channel="newApplicationChannel">

    <int:transformer>
        ...
    </int:transformer>

    <si-xml:unmarshalling-transformer unmarshaller="xxMarshaller"/>

    <!-- enrich header with necessary data -->
    <int:header-enricher>
        ...
    </int:header-enricher>

    <!-- transform xx to yy -->
    <int:transformer ref="xxToYyTransformer"/>

    <!-- call yyy service -->
    <int:gateway request-channel="yyyServiceRequestChannel"/>

</int:chain>

当我将delayer添加到链中时,它很有用,但这不是一个很好的解决方案。

我的问题是,我是否使用taskExecutor错了?我怎样才能使调用异步?我不想使用队列,因为我不需要重复轮询事件。

http-apr-8080-exec-2 14:39:23,530 DEBUG DirectChannel:224 - preSend on channel 'apiRequestChannel'
http-apr-8080-exec-2 14:39:23,534 DEBUG MessageHandlerChain:67 - org.springframework.integration.handler.MessageHandlerChain#4
http-apr-8080-exec-2 14:39:23,535 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler#4ac5c32e
http-apr-8080-exec-2 14:39:23,557 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler#4ac5c32e' sending reply 
http-apr-8080-exec-2 14:39:23,557 DEBUG HeaderValueRouter:67 - (inner bean)#16 received message: 
http-apr-8080-exec-2 14:39:23,558 DEBUG DirectChannel:224 - preSend on channel 'naRequestChannel', message: 
http-apr-8080-exec-2 14:39:23,558 DEBUG MessageHandlerChain:67 - org.springframework.integration.handler.MessageHandlerChain#33 received message: 
http-apr-8080-exec-2 14:39:23,558 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler@3cbcf04e received message: 
http-apr-8080-exec-2 14:39:23,565 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler@3cbcf04e' sending reply 
http-apr-8080-exec-2 14:39:23,566 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler#6a5c2445 received message: 
http-apr-8080-exec-2 14:39:23,594 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler#6a5c2445' sending reply 
http-apr-8080-exec-2 14:39:23,595 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler#47516490 received message: 
http-apr-8080-exec-2 14:39:23,596 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler#47516490' sending reply 
http-apr-8080-exec-2 14:39:23,596 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler@2342f67d received message: 
http-apr-8080-exec-2 14:39:23,597 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler@2342f67d' sending reply 
http-apr-8080-exec-2 14:39:23,598 DEBUG RequestReplyMessageHandlerAdapter:67 - (inner bean)#231 received message: 
http-apr-8080-exec-2 14:39:23,600 DEBUG DirectChannel:224 - preSend on channel 'dossierAddEventRequestChannel', message: 
http-apr-8080-exec-2 14:39:23,601 DEBUG PayloadTypeRouter:67 - (inner bean)#250 received message: 
http-apr-8080-exec-2 14:39:23,602 DEBUG DirectChannel:224 - preSend on channel 'dossierAddEventRequestGenericChannel', message: 
http-apr-8080-exec-2 14:39:23,602 DEBUG MessageHandlerChain:67 - org.springframework.integration.handler.MessageHandlerChain#41 received message: 
http-apr-8080-exec-2 14:39:23,603 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler#23bdb02e received message: http-apr-8080-exec-2 14:39:23,603 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler#23bdb02e' sending reply http-apr-8080-exec-2 14:39:23,604 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler@54054c41 received message: http-apr-8080-exec-2 14:39:23,606 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler@54054c41' sending reply http-apr-8080-exec-2 14:39:23,606 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'dossierAddEventRequestGenericChannel', message: http-apr-8080-exec-2 14:39:23,607 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'dossierAddEventRequestChannel', message: 
http-apr-8080-exec-2 14:39:23,607 DEBUG GatewayProxyFactoryBean:134 - Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.gateway.GatewayProxyFactoryBean#2e29d50d' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
http-apr-8080-exec-2 14:39:23,608 DEBUG RequestReplyMessageHandlerAdapter:156 - handler '(inner bean)#231' sending reply Message: http-apr-8080-exec-2 14:39:23,608 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler@3f03c0ad received message: 
http-apr-8080-exec-2 14:39:23,609 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler@3f03c0ad' sending reply http-apr-8080-exec-2 14:39:23,611 DEBUG RequestReplyMessageHandlerAdapter:67 - (inner bean)#232 received message: http-apr-8080-exec-2 14:39:23,612 DEBUG DirectChannel:224 - preSend http-apr-8080-exec-2 14:39:23,612 DEBUG ServiceActivatingHandler:67 - ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@4149888e] received http-apr-8080-exec-2 14:39:23,614 DEBUG DirectChannel:224 - preSend on channel 'dossierServiceRequestRouter', message: http-apr-8080-exec-2 14:39:23,614 DEBUG PayloadTypeRouter:67 - (inner bean)#17 received message: 
http-apr-8080-exec-2 14:39:23,615 DEBUG DirectChannel:224 - preSend on channel 'dossierServiceJaxbRequestChannel', message: http-apr-8080-exec-2 14:39:23,616 DEBUG MessageHandlerChain:67 - org.springframework.integration.handler.MessageHandlerChain#5 received message: 
http-apr-8080-exec-2 14:39:23,616 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler#7d8e9adf received message: http-apr-8080-exec-2 14:39:23,634 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler#7d8e9adf' sending reply http-apr-8080-exec-2 14:39:23,635 DEBUG RequestReplyMessageHandlerAdapter:67 - (inner bean)#18 received message: [Payload=[#document: null]][Headers={timestamp=1372768763634, http-apr-8080-exec-2 14:39:23,636 DEBUG DirectChannel:224 - preSend on channel 'dossierServiceDocumentRequestChannel', message: 
http-apr-8080-exec-2 14:39:23,636 DEBUG SimpleWebServiceOutboundGateway:67 - org.springframework.integration.ws.SimpleWebServiceOutboundGateway#0 received message: http-apr-8080-exec-2 14:39:24,206 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'dossierServiceDocumentRequestChannel', message: [Payload=[#document: null]][Headers={timestamp=1372768763636, id=a193877c-0faf-4573-b6b4-97ca3cd25f66, errorChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@3875c597, xp_dossierEvent_operator_username=afs-process, xp_dossierEvent_name=NewApplication, replyChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@3875c597, xp_dossierEvent_dateTime=2013-07-02T14:39:23, xp_dossierEvent_details=Nieuwe aanvraag aangemaakt, xp_dossierEvent_operator_name=AFS Proces, xp_endUser=nl.vwpfs.pos.bpf.EndUser@598ef578, xp_businessFunctionName=NewApplication}]
http-apr-8080-exec-2 14:39:24,206 DEBUG GatewayProxyFactoryBean:134 - Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.gateway.GatewayProxyFactoryBean#1d59e6df' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
http-apr-8080-exec-2 14:39:24,207 DEBUG RequestReplyMessageHandlerAdapter:156 - handler '(inner bean)#18' sending reply Message: 
http-apr-8080-exec-2 14:39:24,207 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler#79444986 received message: http-apr-8080-exec-2 14:39:24,218 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler#79444986' sending reply http-apr-8080-exec-2 14:39:24,219 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'dossierServiceJaxbRequestChannel', message: http-apr-8080-exec-2 14:39:24,219 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'dossierServiceRequestRouter', message: 
http-apr-8080-exec-2 14:39:24,219 DEBUG GatewayProxyFactoryBean:134 - Unable to attempt conversion of Message payload types. Component 'dossierServiceGateway' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
http-apr-8080-exec-2 14:39:24,220 DEBUG ServiceActivatingHandler:156 - handler 'ServiceActivator for http-apr-8080-exec-2 14:39:24,220 DEBUG GatewayProxyFactoryBean:134 - Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.gateway.GatewayProxyFactoryBean#5e970110' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
http-apr-8080-exec-2 14:39:24,221 DEBUG RequestReplyMessageHandlerAdapter:156 - handler '(inner bean)#232' sending reply Message: http-apr-8080-exec-2 14:39:24,221 DEBUG DirectChannel:224 - preSend on channel 'newApplicationChannel', message: 
http-apr-8080-exec-2 14:39:24,221 DEBUG RecipientListRouter:67 - org.springframework.integration.router.RecipientListRouter#0 received message: http-apr-8080-exec-2 14:39:24,222 DEBUG DirectChannel:224 - preSend on channel 'finishFlowChannel', message: http-apr-8080-exec-2 14:39:24,222 DEBUG MessageHandlerChain:67 - org.springframework.integration.handler.MessageHandlerChain#35 received message: [Payload=nl.vwpfs.pos.xmlcdm.dossier.service.CreateDossierResponse@6b37695c
http-apr-8080-exec-2 14:39:24,222 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler@57316e85 received message: http-apr-8080-exec-2 14:39:24,223 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler@57316e85' sending reply http-apr-8080-exec-2 14:39:24,224 DEBUG DirectChannel:224 - preSend on channel 'apiReplyChannel', message: http-apr-8080-exec-2 14:39:24,224 DEBUG MessageTransformingHandler:67 - http-apr-8080-exec-2 14:39:24,235 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'apiReplyChannel', message: http-apr-8080-exec-2 14:39:24,236 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'finishFlowChannel', message: 
http-apr-8080-exec-2 14:39:24,236 DEBUG ExecutorChannel:224 - preSend on channel 'processEngineChannel', message: 
http-apr-8080-exec-2 14:39:24,239 DEBUG ExecutorChannel:237 - postSend (sent=true) on channel 'processEngineChannel', message: 
taskExecutor-1 14:39:24,239 DEBUG MessageHandlerChain:67 - org.springframework.integration.handler.MessageHandlerChain#34 received message: 
http-apr-8080-exec-2 14:39:24,239 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'newApplicationChannel', message: 
taskExecutor-1 14:39:24,240 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler@289f6ae received message: 
http-apr-8080-exec-2 14:39:24,240 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'naRequestChannel', message: 
http-apr-8080-exec-2 14:39:24,241 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'apiRequestChannel', message: 
taskExecutor-1 14:39:27,817 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler@289f6ae' sending reply Message: 
taskExecutor-1 14:39:27,819 DEBUG RequestReplyMessageHandlerAdapter:67 - (inner bean)#235 received message: 
taskExecutor-1 14:39:27,822 DEBUG DirectChannel:224 - preSend on channel 'sendToProcessEngineChannel', message: 
taskExecutor-1 14:39:27,822 DEBUG MarshallingWebServiceOutboundGateway:67 - org.springframework.integration.ws.MarshallingWebServiceOutboundGateway#0 received message: 
taskExecutor-1 14:39:28,094 DEBUG MarshallingWebServiceOutboundGateway:156 - handler 'org.springframework.integration.ws.MarshallingWebServiceOutboundGateway#0' sending reply 
taskExecutor-1 14:39:28,095 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'sendToProcessEngineChannel', message: 
taskExecutor-1 14:39:28,095 DEBUG GatewayProxyFactoryBean:134 - Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.gateway.GatewayProxyFactoryBean#762589c3' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
taskExecutor-1 14:39:28,095 DEBUG RequestReplyMessageHandlerAdapter:156 - handler '(inner bean)#235' sending reply Message: 

1 个答案:

答案 0 :(得分:0)

它工作得很好......

...
http-apr-8080-exec-2 14:39:24,224 DEBUG DirectChannel:224 - preSend on channel 'apiReplyChannel', message: 
http-apr-8080-exec-2 14:39:24,224 DEBUG MessageTransformingHandler:67 - 
http-apr-8080-exec-2 14:39:24,235 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'apiReplyChannel', message: 
http-apr-8080-exec-2 14:39:24,236 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'finishFlowChannel', message: 
http-apr-8080-exec-2 14:39:24,236 DEBUG ExecutorChannel:224 - preSend on channel 'processEngineChannel', message: 
http-apr-8080-exec-2 14:39:24,239 DEBUG ExecutorChannel:237 - postSend (sent=true) on channel 'processEngineChannel', message: 
taskExecutor-1 14:39:24,239 DEBUG MessageHandlerChain:67 - org.springframework.integration.handler.MessageHandlerChain#34 received message: 
http-apr-8080-exec-2 14:39:24,239 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'newApplicationChannel', message: 
taskExecutor-1 14:39:24,240 DEBUG MessageTransformingHandler:67 - org.springframework.integration.transformer.MessageTransformingHandler@289f6ae received message: 
http-apr-8080-exec-2 14:39:24,240 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'naRequestChannel', message: 
http-apr-8080-exec-2 14:39:24,241 DEBUG DirectChannel:237 - postSend (sent=true) on channel 'apiRequestChannel', message: 
taskExecutor-1 14:39:27,817 DEBUG MessageTransformingHandler:156 - handler 'org.springframework.integration.transformer.MessageTransformingHandler@289f6ae' sending reply Message: 
...

如您所见,...exec-2线程在apiReplyChannel上发送回复,然后在processEngineChannel上发送(preSend和postSend背对背)并移交给线程taskExecutor-1然后开始处理该通道上的流 - 链,变换器等。

...exec-2主题继续完成其工作(以apiRequestChannel上的postSend结尾。

但是,我发现你在processEngineChannel链上没有输出通道 - 框架将尝试将该回复发送到消息的replyChannel标题中的任何内容 - 如果你想丢弃你应该设置的回复链的output-channel到nullChannel。