Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

CSV to XML using DataWeave and Active MQ configuration

DZone's Guide to

CSV to XML using DataWeave and Active MQ configuration

Follow along with this how-to in order convert info from CSV to XML using a few simple tools.

· Integration Zone
Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

Use Case: Getting the data from a large CSV file, combining the full data into a single XML file, and posting it to the Active MQ.

Objective: Conversion from CSV to XML using DataWeave and posting data to the Active MQ.

Steps:

1. Create a new project:

File > New > Mule Project

Image title


Image title


2.  Drop a file adapter from the connector section of the palate, and make the below entries.             

Image title

Image title


3. Now to convert CSV data to the XML format, drop the Transform message component right after the file adapter.                      

Image title                          

4. Now double-click on the Transform message and set the metadata for the input payload.

            a. Right-click on the left area (input area).

            b. Select "Set Metadata."

Image title

        c. Follow the marked steps and choose the sample input CSV file.

Image title


5.  Now it's time to set the target metadata for the transform message. To achieve this, I used a trick by dropping the logger after the transform message and defining the input metadata for it.

Image title

    a. Drag the logger after the transfrom message.

    b. Click on the logger and in the bottom cofiguration, click on the metadata tab (as shown in the snapshot).

    c. Follow the same steps as step 4 for setting metadata as XML. Here you can use XSD.

Image title


6. Now we have set the metadata for both input and output of the transform message. It's time to set the logic to convert the CSV data to XML.

  a. Cclick on the transform message again and do the transformation by dragging and dropping the input nodes to the output nodes.

Image title

You can see the generated DataWeave code right-hand side.

7. It's time to setup the JMS adapter for the Active MQ.

   a. Drop the JMS connector after the logger.

Image title



    b. In the configuration, click on the green button and select "Active MQ."


Image title

   c. A popup will come up for Active MQ configuration, just enter the connection details of your Active MQ and click OK.

Image title

   

d.  Now just enter the name of your Queue or topic and save all the artifacts.

Image title


8. That's it! Now you can run the project and can get the desired XML output in the Active MQ.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

Topics:
active mq ,mule esb ,csv conversion ,mulesoft ,integration ,jms

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}