Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is a sample to show how we can change our existing messaging service for requirement or improvement. Here we use a load balance support as example.

Build the sample

Imagine that we have a message handling system built before to collect some information from our client and then process and record them. We have a simple processor that only display the information. This scenario can be constructed by using the following XML route configuration.

Code Block
xml
xml

<route>
  <from uri="file:src/data?noop=true"/>
      
  <!-- Print the message to standard out, just as a test -->
  <convertBodyTo type="java.lang.String"/>
  <to uri="stream:out"/> 
      
  <to uri="activemq:personnel.records"/>
</route>

<route>
  <from uri="activemq:personnel.records"/>
  <choice>
     <when>
       <xpath>/person/city = 'London'</xpath>
       <to uri="file:target/messages/uk"/>
     </when>
     <otherwise>
       <to uri="file:target/messages/others"/>
     </otherwise>
  </choice>
 </route>

For more instruction to build your sample, read the Camel Maven Archetypes page. The above routes are the default configuration for your new sample, so you can get started with it easily.
In this scenario, the first route is responsible to collect data from a directory: src/data, print it to standard output console and deliver it to a message queue to further processing. Then, another route get messages from the queue, and use Content Based Router to sort out them. The messages for person in London are stored in the directory: target/messages/uk, and others in target/messages/others. You can run this sample using command:

Code Block

mvn jetty:run-war

Use Web Console to add load balance support