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

发布于 2025-01-10 21:01:31 字数 3304 浏览 0 评论 0原文

在 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 消息来自哪里。

In my flow in Mule 4, I iterate over multiple files to get data from them and transform them to json. I use a parallel ForEach component to do this. Here are the expected outputs from both of these calls:

result 1:

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

result 2:

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

When I make the call I get these outputs combined together however, I also get the below message with garbled characters mixed with them:

    ��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"
  }

I get the same message before each result. How can I get rid of the above text and get the expected output only?

EDIT:
Below is the XML of the flow:

<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>

There are only two components in the loop. One reads the data from a csv file and then a transform message component transforms it to JSON. I have absolutely no idea where that java message comes from.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我们只是彼此的过ke 2025-01-17 21:01:31

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

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

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

As Aled mentioned, you are seeing the serialized java object. You can add a transform message after parallel-foreach to get the JSON message.

To get the list of payloads, use the following script in a transform message or set payload.

%dw 2.0
output application/json
---
payload.payload
少年亿悲伤 2025-01-17 21:01:31

您可以在合并之前尝试更改有效负载类型吗?像这样的事情:

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

Can you try changing the Payload type before merging it? Something like this:

((write(payload.message, "application/json")) 
黎歌 2025-01-17 21:01:31

您所看到的是 Java 对象的序列化。因为问题中没有足够的信息来提供更具体的答案,所以我将做出有根据的猜测,并假设您看到的是一条消息或消息列表,而不是您期望看到的有效负载。请记住,并行 foreach 与标准 foreach 不同,返回消息列表,而不是有效负载列表。 消息除了属性之外还包含有效负载。您只需从列表中的每条消息中获取有效负载。

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

What you are seeing is a serialization of Java objects. Because there is not enough information in the question for a more concrete answer I will make an educated guess and assume that you are seeing a message, or message list instead of the payload that you expect to see. Remember that the parallel foreach, unlike the standard foreach, returns a list of messages, not a list of payloads. The message contains the payload in addition to attributes. You need to take only the payload from each message of the list.

Also try to use the latest release of Mule 4 and if possible the latest cumulative patching to avoid known issues of previous releases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文