gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:46:14 24 4
gpt4 key购买 nike

我们正在尝试这样一种场景:我们在一个有效载荷中发送请求列表,根据一些 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>

在请求 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</cur‌​rency></pricePerTicket><quantity>1</quantity><section>CENTER ORCHESTRA</section><rows>M</rows><seats>2</seats><splitOption>NONE</splitOption>‌​</listing>

最佳答案

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

  1. 使用xpath('<expression>', payload)而不是 xpath('<expression>')作为拆分器表达式。拆分器在将有效负载拆分为 block 方面仍然可以正常工作,但是,子流中的 xpath 调用针对原始有效负载的当前 block 而不是整个原始有效负载,就像您的示例中那样。 @Ryan Carter 在评论中提到了这一点,并且仍然适用于 Anypoint Studio 3.5.2。
  2. 使用与@David Dossot 提到的您正在设置的项目相对应的当前版本适当的 setter 组件。设置流量变量 <set-variable>对应于您当前正在做的事情。
    • <set-property>用于设置出站属性
    • <set-variable>用于设置流量变量
    • <set-session-variable>用于设置 session 变量
  3. 使用<foreach>范围而不是拆分器聚合器模式。使用 XML 的拆分器聚合器的缺点是您获得了 DOM 对象的集合,您必须将这些对象合并为一个对象,然后再发送回调用者。如果您使用 foreach,那么您可以修改集合中的现有对象,因为 foreach 使用对原始负载的引用。
    • How to use XPath with foreach .
    • 如果需要替换foreach集合中当前项的内容,可以使用rootMessage.payload[counter-1] = payload;其中右侧有效负载是当前 for-each 迭代的有效负载,仅对该迭代有效,而 rootMessage.payload 是整个集合。您可以试一试,看看它与 foreach 以及 DOM 负载和 XPath 集合的配合情况如何。

关于拆分后的 Mule 消息属性在一个字段中显示拆分消息的所有属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24416120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com