(已解决)M子4-转换后将有效负载发送到Azure文件共享

时间:2020-07-30 07:55:59

标签: azure-storage mulesoft mule4

简单的流程来获取xml,并在添加日期之后将其发送回Azure File Share。我正在使用Azure Storage Connector

Payload after Download file from root directory

Payload after Set Payload

Payload after Transform Message

使用流将根目录中的文件上传失败,并显示以下错误:

ERROR 2020-07-30 10:44:15,756 [[MuleRuntime].uber.03: [azure_test].azure_testFlow.BLOCKING @7dde3fa] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
********************************************************************************
Message               : File length must be greater than 0 bytes.
Element               : azure_testFlow/processors/6 @ azure_test:azure_test.xml:33 (Upload file in root directory with stream)
Element DSL           : <azure-storage:upload-file-in-root-directory-with-stream doc:name="Upload file in root directory with stream" doc:id="93b6bb01-c42c-454a-aaca-3c3325534b5d" config-ref="Azure_Storage_Config" target="payload">
                        <azure-storage:rootfile fileName="output" fileStream="#[payload]" shareName="dev"></azure-storage:rootfile>
                        </azure-storage:upload-file-in-root-directory-with-stream>
Error type            : MULE:UNKNOWN
FlowStack             : at azure_testFlow(azure_testFlow/processors/6 @ azure_test:azure_test.xml:33 (Upload file in root directory with stream))
--------------------------------------------------------------------------------

如图所示,有效载荷在前两个处理器(不包括记录器)之后用引号引起来。但是,在“转换消息”之后,引号消失了,当我单击“更新值”时,它为空。这是否意味着转换消息后的输出有效负载不再在流中?如果可以的话,如何使转换输出流成为可能?转换后的Logger会在控制台中写入新的有效负载。

编辑:

这是输入文件:

<data>DATA</data>

流的XML:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:azure-storage="http://www.mulesoft.org/schema/mule/azure-storage"
    xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/azure-storage http://www.mulesoft.org/schema/mule/azure-storage/current/mule-azure-storage.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <azure-storage:config name="Azure_Storage_Config" doc:name="Azure Storage Config" doc:id="ced6e7d8-da1c-4d1e-b02c-fb990de78ed1" >
        <azure-storage:sas-token-config-connection accountName="account" sasToken="token"/>
    </azure-storage:config>
    <flow name="azure_testFlow" doc:id="bcb34135-5d34-4fd8-b794-1a6a668d6f53" >
        <azure-storage:download-file-from-root-directory doc:name="Download file from root directory" doc:id="c3893681-5489-4ee0-8058-38b189895a01" config-ref="Azure_Storage_Config">
            <azure-storage:root-file fileName="input" shareName="dev" />
        </azure-storage:download-file-from-root-directory>
        <logger level="INFO" doc:name="Logger" doc:id="183d3636-9ef6-4fb0-b144-c880949dda36" message='#[payload]'/>
        <set-payload value="#[payload]" doc:name="Set Payload" doc:id="20769233-90e1-4c5c-9556-b8e582cd638c" mimeType="application/xml" encoding="UTF-8"/>
        <logger level="INFO" doc:name="Logger" doc:id="62d02465-952a-4de2-9c9d-a8319f3ddb96" message="#[payload]" />
        <ee:transform doc:name="Transform Message" doc:id="04150311-2a96-4215-b252-07a36c3b133e" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/xml writeDeclaration=false
--- 
{
    data: payload.data ++ now() as String {format: "yyyyMMddHHmm"}
}]]></ee:set-payload>
            </ee:message>
            <ee:variables >
            </ee:variables>
        </ee:transform>
        <azure-storage:upload-file-in-root-directory-with-stream doc:name="Upload file in root directory with stream" doc:id="9a2f25b6-270f-4cff-bc87-141d7e30147e" config-ref="Azure_Storage_Config">
                    <azure-storage:rootfile fileName="outputStream" fileStream="#[payload]" shareName="dev" />
                </azure-storage:upload-file-in-root-directory-with-stream>
        <file:write doc:name="Write" doc:id="f3dc6f68-06aa-4755-b9a6-09cad8224fb7" path="C:\Users\jespe\outputFile" />
        <azure-storage:upload-file-in-root-directory doc:name="Upload file in root directory" doc:id="2ccac879-d196-41e1-8a64-58494421ee68" config-ref="Azure_Storage_Config">
            <azure-storage:file fileName="outputFile" shareName="dev" path="C:\Users\jespe\outputFile" />
        </azure-storage:upload-file-in-root-directory>
        <file:delete doc:name="Delete" doc:id="852758e7-94e6-43e2-9421-285f1bb85f26" path="C:\Users\jespe\outputFile" />
    </flow>
</mule>

删除记录器,然后再上传带有流的文件。调试器仍然显示转换后的有效负载。

Without Logger

编辑2:

@ jan-h的回答确实是解决方案。但是,在“转换消息”中设置deferred = true对我不起作用。必须在“使用流上传文件”中进行设置。

Solution

2 个答案:

答案 0 :(得分:0)

看起来上一次DataWeave转换返回了不可重复的流,因此它已在记录器中使用。尝试删除最后一个记录器,以查看是否显示有效负载。

最好共享流的XML。仅凭屏幕截图就无法了解它在做什么。

答案 1 :(得分:0)

在最后一个数据编织中添加deferred = true。 像这样:输出application / xml deferred = true