首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拆分后的Mule Message属性在一个字段中显示拆分消息的所有属性值。

拆分后的Mule Message属性在一个字段中显示拆分消息的所有属性值。
EN

Stack Overflow用户
提问于 2014-06-25 18:38:03
回答 1查看 1.3K关注 0票数 3

我们正在尝试这样一个场景:我们在一个有效负载中发送一个请求列表,根据某些xpath将该有效负载拆分到单个请求,进行单独的http出站调用并将其聚合到后面。整个流程运行良好,但是我们尝试使用从拆分的消息有效负载中提取的值添加调用属性,并且它总是显示所有拆分消息的值。下面是我拥有的骡子流配置:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd">
    <!-- HTTPS Connection Configuration With CERTS -->
    <https:connector name="HTTP_HTTPS" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP-HTTPS">
        <https:tls-server  path="/Users/rkesara/opt/MULE/truststore/cacerts" storePassword="changeit" />
    </https:connector>

    <!-- List of transformers that might be useful for this flow -->
    <mulexml:dom-to-xml-transformer outputEncoding="UTF-8" name="DOM_to_XML" doc:name="DOM to XML"/>

    <!-- Root flow that can trigger pull and push functionality -->
    <flow name="PushInventoryFlow" doc:name="PushInventoryFlow">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        <logger message="PushInventoryFlow - Listing requests payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>

        <logger message="PullAndPushInventoryFlow - Splitting listing requests..." level="INFO" doc:name="Logger"/>
        <splitter enableCorrelation="ALWAYS" expression="#[xpath('//listings/listing')]" doc:name="ListingRequestSplitter"/>
        <logger message="PullAndPushInventoryFlow - Number of listing requests found after bunlding : #[header:MULE_CORRELATION_GROUP_SIZE] - current request number : #[header:MULE_CORRELATION_SEQUENCE]" level="INFO" doc:name="Logger"/>

        <flow-ref name="ListingMessageProcessorFlow" />

        <collection-aggregator />        
        <logger message="Aggregated Payload-&gt; #[payload]" level="INFO" doc:name="Logger"/>
   </flow>

   <flow name="ListingMessageProcessorFlow" doc:name="ListingMessageProcessorFlow">

        <message-properties-transformer scope="invocation" doc:name="Remember correlation">
            <add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_ID]" key="cid" />
            <add-message-property value="#[header:OUTBOUND:MULE_CORRELATION_GROUP_SIZE]" key="cgs" />

            <add-message-property value="#[xpath://listing/section]" key="section" />
        </message-properties-transformer>

        <logger message="ListingMessageProcessorFlow - Invoking listingAPI for Section: #[header:INVOCATION:section] with request payload : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
        <https:outbound-endpoint exchange-pattern="request-response" host="api-dev.srwd10.com" port="443" path="inventory/listings/v1/" method="POST" doc:name="HTTP" connector-ref="HTTP_HTTPS" transformer-refs="DOM_to_XML" contentType="application/xml" mimeType="application/xml">
            <message-properties-transformer scope="outbound">
                <add-message-property key="Authorization" value="Bearer blahblahblah" />
                <add-message-property key="TARGET_HOST" value="srwq12" />
                <add-message-property key="Acccept" value="application/xml" />
            </message-properties-transformer>
        </https:outbound-endpoint>
        <logger message="ListingMessageProcessorFlow - Listing API response : #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>

        <message-properties-transformer scope="outbound">
            <add-message-property value="#[header:INVOCATION:cid]" key="MULE_CORRELATION_ID" />
            <add-message-property value="#[header:INVOCATION:cgs]" key="MULE_CORRELATION_GROUP_SIZE" />
        </message-properties-transformer>

    </flow>

</mule>

在请求xml之后:

代码语言:javascript
复制
<listings>
   <listing>
      <eventId>4457573</eventId>
      <eventDescription>The Book of Mormon Houston</eventDescription>
      <pricePerTicket>
         <amount>900</amount>
         <currency>USD</currency>
      </pricePerTicket>
      <quantity>1</quantity>
      <section>CENTER ORCHESTRA</section>
      <rows>M</rows>
      <seats>2</seats>
      <splitOption>NONE</splitOption>
   </listing>
   <listing>
      <eventId>4457573</eventId>
      <eventDescription>The Book of Mormon Houston</eventDescription>
      <pricePerTicket>
         <amount>902</amount>
         <currency>USD</currency>
      </pricePerTicket>
      <quantity>1</quantity>
      <section>CENTER ORCHESTRA</section>
      <rows>M</rows>
      <seats>1</seats>
      <splitOption>NONE</splitOption>
   </listing>
   <listing>
      <eventId>4457573</eventId>
      <eventDescription>The Book of Mormon Houston</eventDescription>
      <pricePerTicket>
         <amount>905</amount>
         <currency>USD</currency>
      </pricePerTicket>
      <quantity>2</quantity>
      <section>CENTER ORCHESTRA</section>
      <rows>M</rows>
      <seats>4,6</seats>
      <splitOption>NONE</splitOption>
   </listing>
   <listing>
      <eventId>4457573</eventId>
      <eventDescription>The Book of Mormon Houston</eventDescription>
      <pricePerTicket>
         <amount>906</amount>
         <currency>USD</currency>
      </pricePerTicket>
      <quantity>1</quantity>
      <section>CENTER ORCHESTRA</section>
      <rows>M</rows>
      <seats>5</seats>
      <splitOption>NONE</splitOption>
   </listing>
   <listing>
      <eventId>4457573</eventId>
      <eventDescription>The Book of Mormon Houston</eventDescription>
      <pricePerTicket>
         <amount>907</amount>
         <currency>USD</currency>
      </pricePerTicket>
      <quantity>2</quantity>
      <section>CENTER ORCHESTRA</section>
      <rows>M</rows>
      <seats>7,9</seats>
      <splitOption>NONE</splitOption>
   </listing>
   <listing>
      <eventId>4457573</eventId>
      <eventDescription>The Book of Mormon Houston</eventDescription>
      <pricePerTicket>
         <amount>908</amount>
         <currency>USD</currency>
      </pricePerTicket>
      <quantity>2</quantity>
      <section>CENTER ORCHESTRA</section>
      <rows>M</rows>
      <seats>3,8</seats>
      <splitOption>NONE</splitOption>
   </listing>
   <listing>
      <eventId>4457573</eventId>
      <eventDescription>The Book of Mormon Houston</eventDescription>
      <pricePerTicket>
         <amount>909</amount>
         <currency>USD</currency>
      </pricePerTicket>
      <quantity>1</quantity>
      <section>CENTER ORCHESTRA</section>
      <rows>M</rows>
      <seats>10</seats>
      <splitOption>NONE</splitOption>
   </listing>
</listings>

下面是我们在日志中看到的行为:

代码语言:javascript
复制
INFO  2014-06-25 11:29:07,860 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PushInventoryFlow - Number of listing requests found after bunlding : 7 - current request number : 1
INFO  2014-06-25 11:29:07,862 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: ListingMessageProcessorFlow - Invoking listingAPI for Section: [CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA] with request payload : <listing><eventId>4457573</eventId><eventDescription>The Book of Mormon Houston</eventDescription><pricePerTicket><amount>900</amount><currency>USD</currency></pricePerTicket><quantity>1</quantity><section>CENTER ORCHESTRA</section><rows>M</rows><seats>2</seats><splitOption>NONE</splitOption></listing>
INFO  2014-06-25 11:29:12,200 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: ListingMessageProcessorFlow - Listing API response Payload: {"listing":{"id":"1082835915","status":"ACTIVE"}}
INFO  2014-06-25 11:29:12,201 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PushInventoryFlow - Number of listing requests found after bunlding : 7 - current request number : 2
INFO  2014-06-25 11:29:12,202 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: ListingMessageProcessorFlow - Invoking listingAPI for Section: [CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA] with request payload : <listing><eventId>4457573</eventId><eventDescription>The Book of Mormon Houston</eventDescription><pricePerTicket><amount>902</amount><currency>USD</currency></pricePerTicket><quantity>1</quantity><section>CENTER ORCHESTRA</section><rows>M</rows><seats>1</seats><splitOption>NONE</splitOption></listing>
INFO  2014-06-25 11:29:12,695 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: ListingMessageProcessorFlow - Listing API response Payload: {"listing":{"id":"1082835916","status":"ACTIVE"}}
INFO  2014-06-25 11:29:12,695 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: PushInventoryFlow - Number of listing requests found after bunlding : 7 - current request number : 3
INFO  2014-06-25 11:29:12,697 [[telecharge].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: ListingMessageProcessorFlow - Invoking listingAPI for Section: [CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA] with request payload : <listing><eventId>4457573</eventId><eventDescription>The Book of Mormon Houston</eventDescription><pricePerTicket><amount>905</amount><currency>USD</currency></pricePerTicket><quantity>2</quantity><section>CENTER ORCHESTRA</section><rows>M</rows><seats>4,6</seats><splitOption>NONE</splitOption></listing>

有人能帮我指出这个问题吗。只要是FYI,我就会面临一个与那个xpath值的set变量不同的问题。此时,我希望看到,对于每一次调用,我都维护单个拆分消息所具有的值,但在这里,它得到了所有拆分消息的值。

我的问题在于这个价值--只是为了更多地解释它。

代码语言:javascript
复制
ListingMessageProcessorFlow - Invoking listingAPI for Section:

[CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA]

请求有效载荷:

代码语言:javascript
复制
<listing><eventId>4457573</eventId><eventDescription>The Book of Mormon Houston</eventDescription><pricePerTicket><amount>900</amount><currency>USD</cur‌​rency></pricePerTicket><quantity>1</quantity><section>CENTER ORCHESTRA</section><rows>M</rows><seats>2</seats><splitOption>NONE</splitOption>‌​</listing>
EN

回答 1

Stack Overflow用户

发布于 2015-02-16 05:39:57

似乎有几件事,你可以做,以改善这一点3.5或3.6。

  1. 使用xpath('<expression>', payload)而不是xpath('<expression>')作为拆分器表达式。拆分器在将有效负载分成块方面仍然运行良好,但是,子流中的xpath调用针对原始有效负载的当前块工作,而不是像在您的示例中所做的那样,处理整个原始有效负载。在@Ryan Carter的评论中提到了这一点,并且仍然适用于任意点的Studio 3.5.2。
  2. 使用当前版本适当的setter组件,这些组件对应于@ Dossot提到的正在设置的项。设置流变量<set-variable>与您当前所做的工作相对应。
    • 用于设置出站属性的<set-property>
    • 用于设置流变量的<set-variable>
    • 用于设置会话变量的<set-session-variable>

  1. 使用<foreach>作用域而不是拆分器-聚合器模式。使用XML的拆分器聚合器的缺点是,在将DOM对象发送回调用方之前,必须将其合并到单个对象中。如果使用foreach,则可以修改集合中的现有对象,因为foreach使用对原始有效负载的引用。
    • How to use XPath with foreach
    • 如果您需要替换foreach集合中当前项的内容,您可以使用rootMessage.payload[counter-1] = payload;,其中右边的有效载荷是当前每个迭代的有效负载,这些迭代仅对该迭代有效,rootMessage.payload是整个集合。您可以四处游玩,看看它如何与foreach、DOM有效负载和XPath集合一起工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24416120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档