我们正在尝试一个场景,我们在一个有效负载中发送请求列表,根据某些 xpath 将该有效负载拆分为单个请求,进行单个 http 出站调用并将它们聚合在后面。整个过程运行良好,但我们尝试使用从拆分消息有效负载中提取的值添加调用属性,并且它始终显示所有拆分消息的值。这是我拥有的骡流配置:
<?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-> #[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 之后:
<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>
这是我们在日志中看到的行为:
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>
有人可以帮我指出这个问题。仅供参考,我在该 xpath 值上遇到了 set-variable 的不同问题。在这一点上,我想看到对于每次调用,我都维护单个拆分消息具有的值,但在这里它获取所有拆分消息的值。
我的问题是这个值 - 只是为了更多地解释它
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</currency></pricePerTicket><quantity>1</quantity><section>CENTER ORCHESTRA</section><rows>M</rows><seats>2</seats><splitOption>NONE</splitOption></listing>