有没有办法在Splitter Aggregator的服务激活器中设置超时?

时间:2018-09-27 09:56:20

标签: spring timeout spring-integration gateway splitter

我创建了一个拆分器聚合器配置,该配置将拆分消息,每条消息将路由到特定的服务激活器。在每个服务激活器内部,它将调用一个网关,该网关使用CXF调用SOAP服务。我尝试将回复超时放入SOAP网关,但是它不起作用,仍然继续等待服务并聚合消息。我现在在代码中所做的就是将回复超时放入Message网关中。

但是问题是,如果一项服务由于超时而失败,那么将进入聚合器的其余消息也将失败,因为它们属于同一消息组。

我还尝试在聚合器中添加send-partial-result-on-expiry =“ true”,但它仍返回超时错误。

是否可以在通道或服务激活器中设置超时?还是在SOAP网关中?这样一来,如果一条消息由于超时而失败,将不会影响成功的消息?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=".....">

<context:component-scan base-package="com.t460.wilkins.services.impl"/>


<!--The gateways and service activators that will call a designated SOAP service using CXF-->
<int:gateway id="FirstGateway" default-request-channel="firstChannel" service-interface="com.t460.wilkins.gateways.FirstGateway"/>    
<int:gateway id="SecondGateway" default-request-channel="secondChannel" service-interface="com.t460.wilkins.gateways.SecondGateway"/>
<int:gateway id="ThirdGateway" default-request-channel="thirdChannel" service-interface="com.t460.wilkins.gateways.ThirdGateway"/>

<int:channel id="firstChannel"/>
<int:service-activator input-channel="firstChannel" ref="firstService" />
<int:channel id="secondChannel"/>
<int:service-activator input-channel="secondChannel" ref="secondService" />
<int:channel id="thirdChannel"/>
<int:service-activator input-channel="thirdChannel" ref="thirdService" />



<!--Configuration for the Splitter Aggregator-->
<!-- The gateway that will invoke the Splitter Aggregator. The gateway that will pass the initial message
and gather the aggregated message-->
<int:gateway id="MessageGateway" service-interface="com.t460.wilkins.gateways.MessageGateway" default-request-channel="asyncSenderChannel" default-reply-channel="asyncSenderChannel" default-reply-timeout="5000"/>

<int:channel id="asyncSenderChannel"/>
<int:channel id="asyncReceiverChannel"/>

<!-- Splitter-->
<int:splitter input-channel="asyncSenderChannel" output-channel="routingChannel" id="messageSplitter" ref="messageSplitter" />
<int:channel id="routingChannel"/>

<!-- Router -->
<int:recipient-list-router id="recipientWithSelector" input-channel="routingChannel">
    <int:recipient channel="firstSplitChannel" selector-expression="headers.msgType eq 'First'"/>
    <int:recipient channel="secondSplitChannel" selector-expression="headers.msgType eq 'Second'"/>
    <int:recipient channel="thirdSplitChannel" selector-expression="headers.msgType eq 'Third'"/>
</int:recipient-list-router>

<int:channel id="firstSplitChannel">
    <int:queue/>
</int:channel>
<int:channel id="secondSplitChannel">
    <int:queue/>
</int:channel>
<int:channel id="thirdSplitChannel">
    <int:queue/>
</int:channel>

<!-- These are the service activators where the splitted messages will be routed. Inside their classes, they each invoke the
an appropriate gateway listed above to get a data from a SOAP service using cxf-->
<int:service-activator input-channel="firstSplitChannel" output-channel="aggregateChannel" 
ref="firstSoapActivator">
    <int:poller receive-timeout="1000" task-executor="taskExecutor" fixed-rate="5"/>
</int:service-activator>

<int:service-activator input-channel="secondSplitChannel" output-channel="aggregateChannel" 
ref="secondSoapActivator">
    <int:poller receive-timeout="1000" task-executor="taskExecutor" fixed-rate="5"/>
</int:service-activator>

<int:service-activator input-channel="thirdSplitChannel" output-channel="aggregateChannel" 
ref="thirdSoapActivator">
    <int:poller receive-timeout="1000" task-executor="taskExecutor" fixed-rate="5"/>
</int:service-activator>

<!--Aggregator-->
<int:channel id="aggregateChannel"/>
<int:aggregator input-channel="aggregateChannel" output-channel="asyncReceiverChannel" id="aggregator"
ref="componentsAggregator" correlation-strategy="componentsCorrelationStrategy"
release-strategy="componentsReleaseStrategy" expire-groups-upon-completion="true" send-partial-result-on-expiry="true"/>

<!--Task Executor-->
<task:executor id="taskExecutor" pool-size="10-1000"
               queue-capacity="5000"/>

---更新----

我尝试删除消息网关的答复超时,并在服务激活器中放入send-timeout =“ 5000”,但是聚合器仍在等待所有消息到达。

我还尝试将答复超时设置在SOAP网关“ FirstGateway”,“ SecondGateway”,“ ThirdGateway”上,但它仍在推送并等待所有消息。

1 个答案:

答案 0 :(得分:0)

首先,您需要考虑使用散点图:https://docs.spring.io/spring-integration/docs/5.0.8.RELEASE/reference/html/messaging-routing-chapter.html#scatter-gathergroup-timeout仍然无济于事的另一点是:不能保证某个群组会及时过期。您需要使用表达式建议以任何方式将错误路由到聚合器。然后,在发布功能中,您可以从最终列表中过滤错误:https://docs.spring.io/spring-integration/docs/5.0.8.RELEASE/reference/html/messaging-endpoints-chapter.html#message-handler-advice-chain