CSV to XML using DataWeave and Active MQ configuration
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.
Join the DZone community and get the full member experience.
Join For FreeDiscover how you can get APIs and microservices to work at true enterprise scale.
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
2. Drop a file adapter from the connector section of the palate, and make the below entries.
3. Now to convert CSV data to the XML format, drop the Transform message component right after the file adapter.
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."
c. Follow the marked steps and choose the sample input CSV file.
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.
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.
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.
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.
b. In the configuration, click on the green button and select "Active MQ."
c. A popup will come up for Active MQ configuration, just enter the connection details of your Active MQ and click OK.
d. Now just enter the name of your Queue or topic and save all the artifacts.
8. That's it! Now you can run the project and can get the desired XML output in the Active MQ.
APIs and microservices are maturing, quickly. Learn what it takes to manage modern APIs and microservices at enterprise scale.
Opinions expressed by DZone contributors are their own.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}