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