Running sample message CSV_4

This sample builds on sample 2 to add a trailer record to the CSV message. It assumes that a trailer is mandatory in the message. 

There are three example messages of this format:

This topic includes instructions for running the sample. It also includes an example of an input test message and a corresponding expected output message, so that you can confirm that the sample has worked.

For a more detailed explanation of the message model used in this sample, refer to  Exploring the Comma Separated Value (CSV) sample.

First input message

The test message used in running this sample is based on the following format:

2005-04-01,X123456IB7,customer details<CRLF>
Bob,Dyson,1 Desolation Row,Orlando,FL,32802,HYT-457-AX<CRLF>
Jimmy,Pace,1002 Misty Mountain Drive,New York,NY,10001,ADU-239-BX<CRLF>
Ralf,McCartney,67 Penny Lane,Las Vegas,NV,89125,JUI-854-CF<CRLF>
Elvis,John,3 Yellow Brick Road,Chicago,IL,60699,GGY-118-AS<CRLF>
Rick,Clayton,461 Ocean Boulevard,Miami,FL,33101,LOP-212-TY<CRLF>
5

<CRLF> represents the characters with ASCII hex code points x'0D' and x'0A'.

Second input message

The test message used in running this sample is based on the following format:

2005-04-01,X123456IB7,customer details<CRLF>
Bob,Dyson,"House of the Rising Sun, 1, Desolation Row",Orlando,FL,32802,HYT-457-AX<CRLF>
Jimmy,Pace,"1002, Misty Mountain Drive",New York,NY,10001,ADU-239-BX<CRLF>
Ralf,McCartney,67 Penny Lane,Las Vegas,NV,89125,JUI-854-CF<CRLF>
Elvis,John,3 Yellow Brick Road,Chicago,IL,60699,GGY-118-AS<CRLF>
Rick,Clayton,"461, Ocean Boulevard",Miami,FL,33101,LOP-212-TY<CRLF>
5

<CRLF> represents the characters with ASCII hex code points x'0D' and x'0A'.

Third input message

The test message used in running this sample is based on the following format:

2005-04-01,X123456IB7,customer details<CRLF>
Bob,Dyson,"""House of the Rising Sun"", 1, Desolation Row",Orlando,FL,32802,HYT-457-AX<CRLF>
Jimmy,Pace,"1002, Misty Mountain Drive",New York,NY,10001,ADU-239-BX<CRLF>
Ralf,McCartney,67 Penny Lane,Las Vegas,NV,89125,JUI-854-CF<CRLF>
Elvis,John,3 Yellow Brick Road,Chicago,IL,60699,GGY-118-AS<CRLF>
Rick,Clayton,"461, Ocean Boulevard",Miami,FL,33101,LOP-212-TY<CRLF>
5

<CRLF> represents the characters with ASCII hex code points x'0D' and x'0A'.

Running the sample

This sample uses the message flow CSV2XML. his message flow contains many input nodes but this sample uses the input node with the queue CSV2XML.IN4. The message flow passes the message through a compute node that changes the format to XML and writes the message out. This causes the CSV message to be parsed into a logical tree and then written in XML format. The output XML message shows the logical structure of the message that was parsed.

To run the sample using the first message:

  1. Switch to the Broker Application Development perspective in the Message Broker Toolkit.
  2. In the Broker Development view, expand the message flow project CSVMessageFlow and open CSV2XML.mbtest.
  3. Click the Invoke icon in the top-right of the editor.
  4. Set Input Node to CSV2XML.IN4.
  5. Ensure Viewer is set to Source.
  6. Click Import Source and select CSV_msg41.dat from project CSVMessageFlow.
  7. Click Send Message. A message is sent to the CSV2XML.IN4 queue.

    The message flow parses the CSV message and writes out the same logical message in XML. The output message is put on the CSV2XML.OUT queue.

  8. You might have to select Source from the Viewer menu to see the message.
  9. Compare this with the expected output message.

    Now try transforming from XML to CSV.

  10. In message flow project CSVMessageFlow, open XML2CSV.mbtest.
  11. Click the Invoke icon in the top-right of the editor.
  12. Set Input Node to XML2CSV.IN.
  13. Ensure Viewer is set to Source.
  14. Click Import Source and select XML_msg41.xml from project CSVMessageFlow.
  15. Click Send Message. A message is sent to the XML2CSV.IN queue.

    The message flow parses the XML message and writes out the same logical message in CSV. The output message is put on the XML2CSV.OUT queue.

  16. Compare this with the original CSV message.

To run the sample using the second message:

  1. Switch to the Broker Application Development perspective in the Message Broker Toolkit.
  2. In the Broker Development view, expand the message flow project CSVMessageFlow and open CSV2XML.mbtest.
  3. Click the Invoke icon in the top-right of the editor.
  4. Set Input Node to CSV2XML.IN4.
  5. Ensure Viewer is set to Source.
  6. Click Import Source and select CSV_msg42.dat from project CSVMessageFlow.
  7. Click Send Message. A message is sent to the CSV2XML.IN4 queue.

    The message flow parses the CSV message and writes out the same logical message in XML. The output message is put on the CSV2XML.OUT queue.

  8. You might have to select Source from the Viewer menu to see the message.
  9. Compare this with the expected output message.

    Now try transforming from XML to CSV.

  10. In message flow project CSVMessageFlow, open XML2CSV.mbtest.
  11. Click the Invoke icon in the top-right of the editor.
  12. Set Input Node to XML2CSV.IN.
  13. Ensure Viewer is set to Source.
  14. Click Import Source and select XML_msg42.xml from project CSVMessageFlow.
  15. Click Send Message. A message is sent to the XML2CSV.IN queue.

    The message flow parses the XML message and writes out the same logical message in CSV. The output message is put on the XML2CSV.OUT queue.

  16. Compare this with the original CSV message.

To run the sample using the third message:

  1. Switch to the Broker Application Development perspective in the Message Broker Toolkit.
  2. In the Broker Development view, expand the message flow project CSVMessageFlow and open CSV2XML.mbtest.
  3. Click the Invoke icon in the top-right of the editor.
  4. Set Input Node to CSV2XML.IN4.
  5. Ensure Viewer is set to Source.
  6. Click Import Source and select CSV_msg43.dat from project CSVMessageFlow.
  7. Click Send Message. A message is sent to the CSV2XML.IN4 queue.

    The message flow parses the CSV message and writes out the same logical message in XML. The output message is put on the CSV2XML.OUT queue.

  8. You might have to select Source from the Viewer menu to see the message.
  9. Compare this with the expected output message.

    Now try transforming from XML to CSV.

  10. In message flow project CSVMessageFlow, open XML2CSV.mbtest.
  11. Click the Invoke icon in the top-right of the editor.
  12. Set Input Node to XML2CSV.IN.
  13. Ensure Viewer is set to Source.
  14. Click Import Source and select XML_msg43.xml from project CSVMessageFlow.
  15. Click Send Message. A message is sent to the XML2CSV.IN queue.

    The message flow parses the XML message and writes out the same logical message in CSV. The output message is put on the XML2CSV.OUT queue.

  16. Compare this with the original CSV message.

If all the steps are successful then the sample is complete.

Now take a look at the message set project and the explanation of this message definition in Exploring the Comma Separated Value (CSV) sample.

Expected output messages

The expected output XML message from input message CSV_msg41 is:

<?xml version="1.0"?>
<CSV_4>
<header>
<requestDate>2005-04-01</requestDate>
<requestID>X123456IB7</requestID>
<requestType>customer details</requestType>
</header>
<customer>
<firstname>Bob</firstname>
<lastname>Dyson</lastname>
<streetaddress>1 Desolation Row</streetaddress>
<cityname>Orlando</cityname>
<statecode>FL</statecode>
<postcode>32802</postcode>
<referencecode>HYT-457-AX</referencecode>
</customer>
<customer>
<firstname>Jimmy</firstname>
<lastname>Pace</lastname>
<streetaddress>1002 Misty Mountain Drive</streetaddress>
<cityname>New York</cityname>
<statecode>NY</statecode>
<postcode>10001</postcode>
<referencecode>ADU-239-BX</referencecode>
</customer>
<customer>
<firstname>Ralf</firstname>
<lastname>McCartney</lastname>
<streetaddress>67 Penny Lane</streetaddress>
<cityname>Las Vegas</cityname>
<statecode>NV</statecode>
<postcode>89125</postcode>
<referencecode>JUI-854-CF</referencecode>
</customer>
<customer>
<firstname>Elvis</firstname>
<lastname>John</lastname>
<streetaddress>3 Yellow Brick Road</streetaddress>
<cityname>Chicago</cityname>
<statecode>IL</statecode>
<postcode>60699</postcode>
<referencecode>GGY-118-AS</referencecode>
</customer>
<customer>
<firstname>Rick</firstname>
<lastname>Clayton</lastname>
<streetaddress>461 Ocean Boulevard</streetaddress>
<cityname>Miami</cityname>
<statecode>FL</statecode>
<postcode>33101</postcode>
<referencecode>LOP-212-TY</referencecode>
</customer>
<trailer>
<totalRecords>5</totalRecords>
</trailer>
</CSV_4>

The expected output XML message from input message CSV_msg42 is:

<?xml version="1.0"?>
<CSV_4>
<header>
<requestDate>2005-04-01</requestDate>
<requestID>X123456IB7</requestID>
<requestType>customer details</requestType>
</header>
<customer>
<firstname>Bob</firstname>
<lastname>Dyson</lastname>
<streetaddress>&quot;House of the Rising Sun, 1, Desolation Row&quot;</streetaddress>
<cityname>Orlando</cityname>
<statecode>FL</statecode>
<postcode>32802</postcode>
<referencecode>HYT-457-AX</referencecode>
</customer>
<customer>
<firstname>Jimmy</firstname>
<lastname>Pace</lastname>
<streetaddress>&quot;1002, Misty Mountain Drive&quot;</streetaddress>
<cityname>New York</cityname>
<statecode>NY</statecode>
<postcode>10001</postcode>
<referencecode>ADU-239-BX</referencecode>
</customer>
<customer>
<firstname>Ralf</firstname>
<lastname>McCartney</lastname>
<streetaddress>67 Penny Lane</streetaddress>
<cityname>Las Vegas</cityname>
<statecode>NV</statecode>
<postcode>89125</postcode>
<referencecode>JUI-854-CF</referencecode>
</customer>
<customer>
<firstname>Elvis</firstname>
<lastname>John</lastname>
<streetaddress>3 Yellow Brick Road</streetaddress>
<cityname>Chicago</cityname>
<statecode>IL</statecode>
<postcode>60699</postcode>
<referencecode>GGY-118-AS</referencecode>
</customer>
<customer>
<firstname>Rick</firstname>
<lastname>Clayton</lastname>
<streetaddress>&quot;461, Ocean Boulevard&quot;</streetaddress>
<cityname>Miami</cityname>
<statecode>FL</statecode>
<postcode>33101</postcode>
<referencecode>LOP-212-TY</referencecode>
</customer>
<trailer>
<totalRecords>5</totalRecords>
</trailer>
</CSV_4>

The expected output XML message from input message CSV_msg43 is:

<?xml version="1.0"?>
<CSV_4>
<header>
<requestDate>2005-04-01</requestDate>
<requestID>X123456IB7</requestID>
<requestType>customer details</requestType>
</header>
<customer>
<firstname>Bob</firstname>
<lastname>Dyson</lastname>
<streetaddress>&quot;House of the Rising Sun&quot;, 1, Desolation Row</streetaddress>
<cityname>Orlando</cityname>
<statecode>FL</statecode>
<postcode>32802</postcode>
<referencecode>HYT-457-AX</referencecode>
</customer>
<customer>
<firstname>Jimmy</firstname>
<lastname>Pace</lastname>
<streetaddress>1002, Misty Mountain Drive</streetaddress>
<cityname>New York</cityname>
<statecode>NY</statecode>
<postcode>10001</postcode>
<referencecode>ADU-239-BX</referencecode>
</customer>
<customer>
<firstname>Ralf</firstname>
<lastname>McCartney</lastname>
<streetaddress>67 Penny Lane</streetaddress>
<cityname>Las Vegas</cityname>
<statecode>NV</statecode>
<postcode>89125</postcode>
<referencecode>JUI-854-CF</referencecode>
</customer>
<customer>
<firstname>Elvis</firstname>
<lastname>John</lastname>
<streetaddress>3 Yellow Brick Road</streetaddress>
<cityname>Chicago</cityname>
<statecode>IL</statecode>
<postcode>60699</postcode>
<referencecode>GGY-118-AS</referencecode>
</customer>
<customer>
<firstname>Rick</firstname>
<lastname>Clayton</lastname>
<streetaddress>461, Ocean Boulevard</streetaddress>
<cityname>Miami</cityname>
<statecode>FL</statecode>
<postcode>33101</postcode>
<referencecode>LOP-212-TY</referencecode>
</customer>
<trailer>
<totalRecords>5</totalRecords>
</trailer>
</CSV_4>

Back to sample home