Search code examples
muledataweavemulesoftmule4

mule 4.4 community edition - how to parse file data which is coming as stream


I am using Community edition Mule 4.4 ( So my understanding is - cannot use Dataweave ( Transform ) Now due to CE cannot use 'Repetable file store stream' ( which is fine ) ( am using repeatable in memory stream )

Now my problem is after I read in the file - how do I parse the contents ? The data all shows up as

org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider

If I could use Dataweave this was simple enough : i.e.

<ee:transform doc:name="Transform Message">
    <ee:message>
    <ee:set-payload>
             <![CDATA[%dw 2.0
                output application/json

                ---

                payload map (value,index)->
                {
                id:value.column_0
                }]]>
        </ee:set-payload>
    </ee:message>
</ee:transform>

But without using Transform component ( since I am using Community Edition Mule runtime 4.4 ) , how do we handle payload which is really a 'Stream' of data ? Thanks

Please see above code , I need to convert the file content ( which is a stream ) into JSON

edit1: Thanks to @aled updating with more details : Below is the file read operation where I am trying to read in a tab delimited file. Was not sure what I should set the outputMimeType so have set it as 'application/csv'

<file:read doc:name="Read Products file" config-ref="File_Config" outputMimeType='application/csv; header=false; separator=|' path="/employee_master/employees.unl" outputEncoding="utf-8">
        <repeatable-in-memory-stream />
    </file:read>

Solution

  • You are thinking about it the wrong way. First, you are looking at the implementation class in Mule, which in Mule 4 you should not be looking at. No file is really a 'stream of data' when you are trying to process it. Is it a binary file? No, clearly if you use map() DataWeave knows how to parse it. So what is the data format of the input file? JSON, CSV, XML, etc? It looks like the correct format is already set so DataWeave is able to parse the input. Really your problem is that you want to transform the data but you can not use a Transform component in the community edition. Also the editing experience will not be good in the UI.

    What you can do in community edition is use a set-payload with an expression. Since the expression language is still DataWeave it will work exactly the same. You will lose the graphical UI of Transform.