【问题标题】:How to manage payload during interaction with multiple endpoints in a SI flow如何在与 SI 流中的多个端点交互期间管理有效负载
【发布时间】:2016-08-24 01:40:31
【问题描述】:

我正在尝试了解可用于在与多个端点通信的 SI 流中处理有效负载的选项。

我有一个使用 int-ws:inbound-gateway 定义的 Web 服务入口点。它接收带有以下负载的 SOAP 消息:

SOAP 请求

<soapenv:Envelope>
  <soapenv:Header/>
  <soapenv:Body>
    <emp:Employee>
     <emp:EmpId>sf</emp:EmpId>
     <emp:EmpName></emp:EmpName>
    </emp:Employee>
   </soapenv:Body>
</soapenv:Envelope>

然后,SI 流提取 EmpId 并将其作为 字符串 有效负载传递给 JMS 队列。 JMS 端点以string 类型的Employee Name 回复。然后 SI 流将 Employee Name 映射到响应消息中的元素 EmpName

SOAP 响应

<soapenv:Envelope>
  <soapenv:Header/>
  <soapenv:Body>
    <emp:Employee>
     <emp:EmpId>sf</emp:EmpId>
     <emp:EmpName>Spring Framework</emp:EmpName>
    </emp:Employee>
   </soapenv:Body>
</soapenv:Envelope>

为了实现这个用例,我使用了 Claim Check 模式。还使用 header 来存储来自 JMS 端点的回复。

考虑到 SI 流可以与除 JMS 端点之外的其他端点(每个端点都有自己的数据交换格式)通信这一事实,如果您可以建议任何其他方法,这将非常有帮助。另外我想避免使用标头来存储 JMS 回复有效负载。

配置文件

<int-ws:inbound-gateway id="ws-inbound-emp-gateway" request-channel="ws-requests"  
                        marshaller="jaxbMarshaller"  unmarshaller="jaxbMarshaller"
                        header-mapper="customMapper"  />

<int:chain input-channel="ws-requests" output-channel="responsePipe">
    <int:claim-check-in message-store="simpleMessageStore"/>
    <int:header-enricher>
      <int:header  name="msgId" expression="payload"/>
    </int:header-enricher>

    <int:transformer   expression="headers['msgId']"/>
    <int:claim-check-out message-store="simpleMessageStore" remove-message="false"/>

    <int:transformer expression="payload.getEmpId()"/>

    <int-jms:outbound-gateway   request-destination="requestQueue" reply-destination="responseQueue" 
                                requires-reply="true"/>     
</int:chain>

<int:chain input-channel="responsePipe"  >
    <int:header-enricher>
      <int:header name="empNameResponse" expression="payload"/>
    </int:header-enricher>

   <int:transformer   expression="headers['msgId']"/>
   <int:claim-check-out message-store="simpleMessageStore" remove-message="true"/>

    <int:enricher>
      <int:property name="empName"  expression="headers['empNameResponse']"/>
    </int:enricher>
</int:chain>

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    对于你的情况,我只看到Content Enricher 模式,它被实现为 &lt;enricher&gt; 在 Spring 集成中。

    因此,您需要将 XML 请求解组到 POJO,例如使用 JAXB。配置多个 &lt;enricher&gt; 并将下游回复映射到 POJO 的适当属性。

    最后,在所有阶段之后,您应该将最终的 POJO 编组回 XML 并通过 SOAP 作为响应发送。

    样本是here

    【讨论】:

    • 谢谢@Artem。您的解决方案非常适合我的用例。
    猜你喜欢
    • 2016-10-22
    • 2015-10-13
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    • 2019-04-09
    相关资源
    最近更新 更多