MuleSoft ForEach 并行循环。输出中包含乱码的不必要消息

MuleSoft ForEach Parallel loop. Unnecessary message with garbled characters in the output

在 Mule 4 的流程中,我遍历多个文件以从中获取数据并将它们转换为 json。我使用并行 ForEach 组件来执行此操作。以下是这两个调用的预期输出:

结果 1:

{
"plant": "CD909837289",
"serial": "SRF",
"product": "CMNPSD"
},
{
 "plant": "CD909837290",
 "serial": "SFG",
 "product": "CMNHSA"
}

结果 2:

{
"plant": "CD909837296",
"serial": "SFG",
"product": "ERTYUI"
},
{
 "plant": "CD909837297",
 "serial": "SVH",
 "product": "SDFGHJ"
}

当我拨打电话时,我将这些输出组合在一起,但是,我还收到以下消息,其中混有乱码:

    ��srjava.util.ArrayListx����a�IsizexpwsrRorg.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementationeJ蹨��L
inboundMaptLjava/util/Map;LoutboundMapq~LtypedAttributest*Lorg/mule/runtime/api/metadata/TypedValue;xpsr3org.mule.runtime.api.util.CaseInsensitiveMapWrappervrD=wny3LbaseMapq~xpsrjava.util.HashMap���`�F
loadFactorI thresholdxp?@wxsq~sq~?@wxsr(org.mule.runtime.api.metadata.TypedValue�i�Қ,��LdataTypet(Lorg/mule/runtime/api/metadata/DataType;LvaluetLjava/lang/Object;xpsr6org.mule.runtime.core.internal.metadata.SimpleDataType�Jd�~�Z
streamTypeLmimeTypet)Lorg/mule/runtime/api/metadata/MediaType;LtypetLjava/lang/Class;xpsr'org.mule.runtime.api.metadata.MediaTypeͬU�q�S�ZdefinedInAppLparamsq~LprimaryTypetLjava/lang/String;LsubTypeq~xpsrjava.util.Collections$EmptyMapY6�Z���xpt*q~pxvr/org.mule.extension.file.api.LocalFileAttributesJ�5��Z    directoryZregularFileJsizeZsymbolicLinkLcreationTimetLjava/time/LocalDateTime;LlastAccessTimeq~LlastModifiedTimeq~xr9org.mule.extension.file.common.api.AbstractFileAttributes���$pLfileNameq~Lpathq~xpsq~tproduct-date.csvt=/Users/dbien_local/Downloads/DATAFORSCORPION/product-date.csvesr
java.time.Ser�]��"H�xpw
��xsq~!w
�*�xsq~!w
��xw��������xz��[
  {
    "plant": "CD909837289",
    "serial": "SRF",
    "product": "CMNPSD"
  },
  {
    "plant": "CD909837290",
    "serial": "SFG",
    "product": "CMNHSA"
  }

我在每个结果之前都收到相同的消息。我怎样才能摆脱上面的文字并只获得预期的输出?

编辑: 下面是流程的XML:

<file:config name="File_Config" doc:name="File Config" doc:id="45e5b346-2497-4422-961b-a04bb5a7bf80" >
    <file:connection workingDir="/Users/dbien_local/Downloads/DATAFORSCORPION" />
</file:config>
<flow name="get-data-ifFlow" doc:id="8d6b11ec-2a24-49b4-82b4-195816aeb8e5" >
    <http:listener doc:name="Listener" doc:id="8937d90f-75f7-43d0-bf20-02f70f9b2073" config-ref="HTTP_Listener_config" path="/data"/>
<parallel-foreach doc:name="Parallel For Each" doc:id="50ca63de-9004-4a52-97f8-9935425c2763" collection='#[["date", "product"]]'>
        <file:read doc:name="Read" doc:id="f3fbadf3-2716-47c6-803b-90edefff67a3" config-ref="File_Config" path='#["/Users/dbien_local/Downloads/data/product-" ++ payload ++ ".csv"]' />
        <ee:transform doc:name="Transform Message" doc:id="cf7d4f97-2144-4a49-958c-323e26b8b00e">
        <ee:message>
            <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload map ( payload01 , indexOfPayload01 ) -> {
    plant: payload01.plant,
    serial: payload01.serial,
    product: payload01.product
}]]></ee:set-payload>
            </ee:message>
    </ee:transform>
            
</parallel-foreach>

循环中只有两个组件。从 csv 文件中读取数据,然后转换消息组件将其转换为 JSON。我完全不知道 java 消息来自哪里。

你能尝试在合并之前更改 Payload 类型吗?像这样:

((write(payload.message, "application/json")) 

您看到的是 Java 对象的序列化。因为问题中没有足够的信息来提供更具体的答案,所以我会做出有根据的猜测,并假设您看到的是一条消息或消息列表,而不是您希望看到的有效负载。请记住,并行 foreach 与标准 foreach 不同,returns 是消息列表,而不是有效负载列表。 message contains the payload in addition to attributes。您只需从列表中的每条消息中获取有效负载。

同时尝试使用最新版本的 Mule 4,如果可能的话,使用最新的累积补丁来避免以前版本的已知问题。

如 Aled 所述,您看到的是序列化的 java 对象。您可以在 parallel-foreach 之后添加转换消息以获取 JSON 消息。

要获取有效负载列表,请在转换消息或设置有效负载中使用以下脚本。

%dw 2.0
output application/json
---
payload.payload