Spring集成流程(出站和入站)

时间:2013-08-07 13:46:45

标签: spring spring-integration

我有一种情况我不知道如何管理它。

我需要的流程如下:

  1. 第一个服务发挥作用,并创建一条需要在链末端检索的消息。

  2. 当第一个服务完成时,我需要通过一个带有特定消息的新服务来调用推送通知服务器,但是有一些与步骤1中创建的信息相关的信息。

  3. 最后,我已成功发送推送通知,我必须检索在步骤1中创建的消息。

  4. 问题是,如何在生成出站网关调用时保留在步骤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>
    

3 个答案:

答案 0 :(得分:3)

我认为你可以用这样的东西来实现这个目标:

  1. 在将信息发送到出站
  2. 之前复制您的信息
  3. 发送一个到出站,另一个发送到某个频道
  4. 使用与出站超时相同的聚合器来“加入”它们,但事实上,您只能从第一步传递消息(我还没有测试过)
  5. 将其发送至json变压器
  6. 要使用这种方法,我相信,您必须将出站和json变换器放在链外以及复制消息的逻辑。

答案 1 :(得分:3)

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

Book's example

在这里你可以看到这本书的例子,如果我以正确的方式理解它,则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"/>

答案 2 :(得分:0)

我可以想到一种方法,即在步骤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>
相关问题