Spring integration Spring集成:分散-聚集,聚集在并行web服务调用后不工作
我正在设置SpringIntegrationFlow来使用来自MQ的消息,并通过创建从MQ消息创建的请求来对web服务调用进行并行调用 下面是spring集成流的样子Spring integration Spring集成:分散-聚集,聚集在并行web服务调用后不工作,spring-integration,scatter,Spring Integration,Scatter,我正在设置SpringIntegrationFlow来使用来自MQ的消息,并通过创建从MQ消息创建的请求来对web服务调用进行并行调用 下面是spring集成流的样子 使用来自IBM MQ的消息,使用Marshaller转换消息并将实体保存到DB 将保存的实体发送到“散布-聚集”通道 分散-聚集通道有两个分配通道,每个分配通道是一个包含以下组件的链 用于进行Webservice调用的Webservice客户端(Service Activator) 将响应转换为实体对象的转换器 将数据保存到数据
- 使用来自IBM MQ的消息,使用Marshaller转换消息并将实体保存到DB
- 将保存的实体发送到“散布-聚集”通道
- 分散-聚集通道有两个分配通道,每个分配通道是一个包含以下组件的链
- 用于进行Webservice调用的Webservice客户端(Service Activator)
- 将响应转换为实体对象的转换器
- 将数据保存到数据库的处理程序
- 从并行webservice调用收集响应,并将从两个并行webservice调用创建的新对象发送到RabbitMQ
<si:service-activator input-channel="transformedEntity"
ref="incidentHandler" output-channel="outputChannelFromMQ" />
<si:scatter-gather input-channel="outputChannelFromMQ"
requires-reply="false" output-channel="gatherResponseOutputChannel" gather-channel="gatherChannel" gather-timeout="4000">
<si:scatterer apply-sequence="true">
<si:recipient channel="distributionChannel1" />
<si:recipient channel="distributionChannel2" />
</si:scatterer>
</si:scatter-gather>
<si:publish-subscribe-channel id="outputChannelFromMQ" apply-sequence="true"
task-executor="taskExecutor" />
<task:executor id="taskExecutor" queue-capacity="25" pool-size="10-10" />
<si:chain id="planngedBagsChain" input-channel="distributionChannel1"
output-channel="gatherChannel">
<si:service-activator ref="webServiceClient1" method="getResponse" />
<si:service-activator ref="serviceHandler1" method="saveToDB" />
</si:chain>
<si:chain id="bagHistoryChain" input-channel="distributionChannel2"
output-channel="gatherChannel">
<si:service-activator ref="webServiceClient2" method="getResponse" />
<si:transformer ref="transformer" />
<si:service-activator ref="serviceHandler2" method="saveToDB" />
</si:chain>
<si:service-activator input-channel="gatherResponseOutputChannel"
ref="responseTransformer" method="receiveResponse" output-channel="toRabbitMQ" />
启用调试日志后,能够找到它发送到的所有通道。在上述配置下,它不会进入正确的gatherer。更改到下面的配置工作
<si:service-activator input-channel="transformedEntity"
ref="incidentHandler" output-channel="outputChannelFromMQ" />
<si:channel id="outputChannelFromMQ"></si:channel>
<si:scatter-gather input-channel="outputChannelFromMQ"
requires-reply="false" scatter-channel="scatterInputChannel" output-channel="toRabbit"
gather-channel="gatherChannel" gather-timeout="4000">
<si:gatherer id="responseGatherer" ref="responseTransformer" release-strategy-expression="size() == 2"/>
</si:scatter-gather>
<si:publish-subscribe-channel id="scatterInputChannel" apply-sequence="true"
task-executor="taskExecutor" />
<task:executor id="taskExecutor" queue-capacity="25" pool-size="10-10" />
<si:chain id="planngedBagsChain" input-channel="scatterInputChannel"
output-channel="gatherChannel">
<si:service-activator ref="webServiceClient1" method="getResponse" />
<si:service-activator ref="serviceHandler1" method="saveToDB" />
</si:chain>
<si:chain id="bagHistoryChain" input-channel="scatterInputChannel"
output-channel="gatherChannel">
<si:service-activator ref="webServiceClient2" method="getResponse" />
<si:transformer ref="transformer" />
<si:service-activator ref="serviceHandler2" method="saveToDB" />
</si:chain>
启用调试日志后,能够找到它发送到的所有通道。在上述配置下,它不会进入正确的gatherer。更改到下面的配置工作
<si:service-activator input-channel="transformedEntity"
ref="incidentHandler" output-channel="outputChannelFromMQ" />
<si:channel id="outputChannelFromMQ"></si:channel>
<si:scatter-gather input-channel="outputChannelFromMQ"
requires-reply="false" scatter-channel="scatterInputChannel" output-channel="toRabbit"
gather-channel="gatherChannel" gather-timeout="4000">
<si:gatherer id="responseGatherer" ref="responseTransformer" release-strategy-expression="size() == 2"/>
</si:scatter-gather>
<si:publish-subscribe-channel id="scatterInputChannel" apply-sequence="true"
task-executor="taskExecutor" />
<task:executor id="taskExecutor" queue-capacity="25" pool-size="10-10" />
<si:chain id="planngedBagsChain" input-channel="scatterInputChannel"
output-channel="gatherChannel">
<si:service-activator ref="webServiceClient1" method="getResponse" />
<si:service-activator ref="serviceHandler1" method="saveToDB" />
</si:chain>
<si:chain id="bagHistoryChain" input-channel="scatterInputChannel"
output-channel="gatherChannel">
<si:service-activator ref="webServiceClient2" method="getResponse" />
<si:transformer ref="transformer" />
<si:service-activator ref="serviceHandler2" method="saveToDB" />
</si:chain>
您的saveToDB
是否返回任何内容?该方法调用的结果将被发送到gatherChannel
。是的,在DB save成功后,webservice客户端将对代码进行调试并返回对象。这不是我要问的。您的
最终都有类似
的内容。根据您的配置,saveToDB
在服务调用后已经发生。因此,问题是:saveToDB
方法中发生了什么?您可以简单地为org.springframework.integration
类别启用DEBUG
日志记录级别,并在日志中看到您的消息是如何传播的,如果我删除requires reply='false'属性并重试,则会得到'org.springframework.integration.handler.ReplyRequiredException:处理程序'org.springframework.integration.scattergather.ScatterGatherHandler#0'没有生成答复,并且其'requiresReply'属性设置为true',所以基本上,应答不是由scattergatherhandler生成的。您的saveToDB
是否返回任何内容?该方法调用的结果将被发送到gatherChannel
。是的,在DB save成功后,webservice客户端将对代码进行调试并返回对象。这不是我要问的。您的
最终都有类似
的内容。根据您的配置,saveToDB
在服务调用后已经发生。因此,问题是:saveToDB
方法中发生了什么?您可以简单地为org.springframework.integration
类别启用DEBUG
日志记录级别,并在日志中看到您的消息是如何传播的,如果我删除requires reply='false'属性并尝试,那么我会得到'org.springframework.integration.handler.ReplyRequiredException:处理程序'org.springframework.integration.scattergather.ScatterGatherHandler#0'不会生成任何回复,并且它的'requiresReply'属性设置为true',因此基本上应答不是由ScatterGatherHandler生成的。