Spring集成流(出站和入站)

Spring集成流(出站和入站),spring,spring-integration,Spring,Spring Integration,我有一种情况,我不知道如何处理 我需要的流程如下: 第一个服务完成它的工作并创建一条需要在链末端检索的消息 当第一个服务完成时,我需要通过一个新服务调用一个推送通知服务器,其中包含一条特定的消息,但包含一些与步骤1中创建的消息相关的信息 最后,如果推送通知已成功发送,则必须检索在步骤1中创建的消息 问题是,当产生出站网关调用并从notification push server向我检索消息时,如何保持在步骤1中创建的消息 <int:chain input-channel="v1.inputC

我有一种情况,我不知道如何处理

我需要的流程如下:

第一个服务完成它的工作并创建一条需要在链末端检索的消息

当第一个服务完成时,我需要通过一个新服务调用一个推送通知服务器,其中包含一条特定的消息,但包含一些与步骤1中创建的消息相关的信息

最后,如果推送通知已成功发送,则必须检索在步骤1中创建的消息

问题是,当产生出站网关调用并从notification push server向我检索消息时,如何保持在步骤1中创建的消息

<int:chain input-channel="v1.inputChannel.input" output-channel="v1.inputChannel.output" send-timeout="50000">

    <int:header-enricher>
        <int:error-channel ref="v1.inputChannel.error" />
    </int:header-enricher>

    <int:service-activator ref="v1.input.service" method="methodName"/>

    <int:service-activator ref="v1.notificationPusher.service" method="pushNotification"/>

    <int-http:outbound-gateway url="http://example.com/api/elements/:element_id/objects" http-method="POST">
        <int-http:uri-variable name="element_id" expression="#pathVariables.elementId"/>
    </int-http:outbound-gateway>
    <!-- here the transformer needs to get the messsage from v1.input.service -->
    <int:object-to-json-transformer/>

</int:chain>

我可以想到一种方法,即在步骤1之后将有效负载存储到报头中,然后在调用步骤3之前检索并重新填充有效负载:

<int:service-activator ref="v1.input.service" method="methodName"/>
<int:header-enricher>
  <int:header name="originalpayload" expression="payload"/>
</int:header-enricher>

<int:service-activator ref="v1.notificationPusher.service" method="pushNotification"/>
<int:enricher expression="headers.originalpayload"/>

<int-http:outbound-gateway url="http://xxx.com/api/elements/:element_id/objects" http-method="POST">
    <int-http:uri-variable name="element_id" expression="#pathVariables.elementId"/>
</int-http:outbound-gateway>

我可以想到一种方法,即在步骤1之后将有效负载存储到报头中,然后在调用步骤3之前检索并重新填充有效负载:

<int:service-activator ref="v1.input.service" method="methodName"/>
<int:header-enricher>
  <int:header name="originalpayload" expression="payload"/>
</int:header-enricher>

<int:service-activator ref="v1.notificationPusher.service" method="pushNotification"/>
<int:enricher expression="headers.originalpayload"/>

<int-http:outbound-gateway url="http://xxx.com/api/elements/:element_id/objects" http-method="POST">
    <int-http:uri-variable name="element_id" expression="#pathVariables.elementId"/>
</int-http:outbound-gateway>

我认为你可以通过这样的方式实现这一点:

在将邮件发送到出站服务器之前复制邮件 将一个发送到出站,另一个发送到某个通道 使用与出站超时相同的聚合器加入它们,但实际上,您只能从第一步传递消息到我没有测试它 将其发送到json转换器
我认为,要使用这种方法,您必须将出站和json转换器以及复制消息的逻辑置于链之外。

我认为您可以通过以下方式实现这一点:

在将邮件发送到出站服务器之前复制邮件 将一个发送到出站,另一个发送到某个通道 使用与出站超时相同的聚合器加入它们,但实际上,您只能从第一步传递消息到我没有测试它 将其发送到json转换器
我认为,要使用这种方法,必须将出站和json转换器以及复制消息的逻辑置于链之外。

在对“Spring Integration in Action”进行了一些研究之后,我认为解决这种情况的最佳选择是使用wire tap模式,将推送通知服务作为辅助流

在这里,您可以看到本书的示例,如果我以正确的方式理解它,那么auditChannel充当与主流分离的二级流

<channel id="debitChannel">
    <interceptors>
    <wire-tap channel="auditChannel"/>
    </interceptors>
</channel>

<service-activator input-channel="debitChannel" method="process">
    <beans:bean class="siia.monitoring.wiretap.DebitService"/>
</service-activator>

<filter input-channel="auditChannel" expression="payload.amount > 10000" output-channel="logger"/>

<logging-channel-adapter id="logger" expression="'auditing debit: ' + payload"/>

在对“SpringIntegrationinAction”进行了一些研究之后,我认为解决这种情况的最佳选择是使用WireTap模式,将推送通知服务作为二级流

在这里,您可以看到本书的示例,如果我以正确的方式理解它,那么auditChannel充当与主流分离的二级流

<channel id="debitChannel">
    <interceptors>
    <wire-tap channel="auditChannel"/>
    </interceptors>
</channel>

<service-activator input-channel="debitChannel" method="process">
    <beans:bean class="siia.monitoring.wiretap.DebitService"/>
</service-activator>

<filter input-channel="auditChannel" expression="payload.amount > 10000" output-channel="logger"/>

<logging-channel-adapter id="logger" expression="'auditing debit: ' + payload"/>

您是否必须等待出站服务器完成其工作?出站和json transformer对象是否可以放在链的外部?我这样认为是因为我必须等待知道通知是否以正确的方式推送,并且基于此,从步骤1开始稍微更改消息。是否必须等待出站完成其工作?出站和json transformer的对象可以放在链之外吗?我这样认为是因为我必须等待知道通知是否以正确的方式推送,并且基于此,对步骤1中的消息进行一点更改。如果我得到正确的消息,我想他希望在之后而不是之前得到它,由于更改消息的人是外部边界,我会使用a而不是a来恢复有效负载,但是,是的,这是a中的常见方法。我认为@drurenia是正确的。如果a尝试在出站呼叫后从报头获取原始负载,我会获取原始负载吗?如果我获取正确,我认为他希望在之后而不是之前获取,因为更改消息的人是outbound,我会使用a而不是an来恢复负载,但是,是的,这是a中的常见方法。我认为@drurenia是正确的。如果在出站调用后尝试从报头获取原始有效负载,我会获取原始有效负载吗?解决方案有点复杂。我已经讨论了出站,对链做了一点更改,pushNotificationService现在单独负责使用threadPoolTaskExecutor调用异步任务,并在内部使用restTemplate进行调用,因此我不必等待任何操作。解决方案有点复杂。我已经讨论了出站,对链做了一点更改,pushNotificationService现在单独负责使用threadPoolTaskExecutor调用异步任务,并在内部使用restTemplate进行调用,因此我不必等待任何事情。