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

拆分后的Mule消息属性在一个字段中显示拆分消息的所有属性值,mule,mule-studio,mule-el,Mule,Mule Studio,Mule El,我们正在尝试这样一种场景:我们在一个负载中发送一个请求列表,根据一些xpath将该负载拆分为单独的请求,进行单独的http出站调用,并在后面聚合它们。整个过程工作正常,但我们尝试使用从拆分消息负载中提取的值添加调用属性,它始终显示所有拆分消息的值。以下是我拥有的mule流配置: <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:https="http://www.mulesoft.org/schema/mule/https"

我们正在尝试这样一种场景:我们在一个负载中发送一个请求列表,根据一些xpath将该负载拆分为单独的请求,进行单独的http出站调用,并在后面聚合它们。整个过程工作正常,但我们尝试使用从拆分消息负载中提取的值添加调用属性,它始终显示所有拆分消息的值。以下是我拥有的mule流配置:

<?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>
对于请求有效负载:

<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>
4457573摩门教胡斯顿中心管弦乐团之书‌​

似乎可以通过第3.5点或第3.6点做一些事情来改进这一点

  • 使用
    xpath(“”,有效负载)
    而不是
    xpath(“”)
    作为拆分器表达式。拆分器在将有效负载拆分为块方面仍然可以正常工作,但是,子流中的xpath调用针对原始有效负载的当前块工作,而不是像您的示例中那样针对整个原始有效负载工作。@Ryan Carter在评论中提到了这一点,并且仍然适用于Anypoint Studio 3.5.2
  • 使用当前版本相应的setter组件,这些组件对应于您正在设置的@David Dossot所提到的项目。设置流量变量
    与您当前正在执行的操作相对应。
    • 用于设置出站属性
    • 用于设置流量变量
    • 用于设置会话变量
  • 使用
    范围而不是拆分器聚合器模式。使用XML的拆分器聚合器的缺点是,您会得到一个DOM对象的集合,在发送回调用方之前,必须将这些对象合并到一个对象中。如果使用foreach,则可以修改集合中的现有对象,因为foreach使用对原始有效负载的引用。
    • 如果需要替换foreach集合中当前项的内容,可以使用
      rootMessage.payload[counter-1]=payload其中,右侧有效载荷是每个迭代的当前有效载荷,该有效载荷仅对该迭代有效,rootMessage.payload是整个集合。您可以仔细研究一下,看看这对foreach、DOM负载和XPath集合的效果如何
      

  • 谢谢你,大卫。把它移到实际问题本身。如果我正在做导致问题的事情,你能帮我解决这个问题吗。我需要在单独拆分的消息中使用section字段值来进一步进行逻辑分析。这是Mule的哪个版本?我看到表达式语法是旧的,不是MEL,所以我假设您使用Mule 3.2或更旧的版本?不确定是否存在相同的问题,但我必须专门将负载传递给xpath函数,以便它以这种方式与拆分器一起工作。否则,后续的xpath函数似乎会使用原始负载或其他功能。“我还没有机会调查它。@大卫-我正在使用3.5.0 Anypoint Studio,但这有关系吗。@瑞安,我认为我的拆分器工作得很好。”。拆分消息后,我试图在流中使用拆分负载的一个元素,当我转储该值时,我会使用逗号分隔的值列表一次性看到所有拆分消息的值。谢谢,我会尝试。
    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>
    
    ListingMessageProcessorFlow - Invoking listingAPI for Section:
    
    [CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA, CENTER ORCHESTRA]
    
    <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>