...
Camel can be configured either by using Spring or directly in Java - which this example does.
We start with creating a CamelContext - which is a container for Components, Routes etc:
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=activemq/camel/trunk/examples/camel-egexample-jms-file/src/main/java/org/apache/camel/samplesexample/jmstofile/CamelJmsToFileSampleCamelJmsToFileExample.java} |
There is more than one way of adding a Component to the CamelContext - explicitly - as we do here when we add the JMS Component:
Wiki Markup |
---|
{snippet:id=e2|lang=java|url=activemq/camel/trunk/examples/camel-egexample-jms-file/src/main/java/org/apache/camel/samplesexample/jmstofile/CamelJmsToFileSampleCamelJmsToFileExample.java} |
or implicitly - when we set up the routing (as we do here for the FileComponent:
Wiki Markup |
---|
{snippet:id=e3|lang=java|url=activemq/camel/trunk/examples/camel-egexample-jms-file/src/main/java/org/apache/camel/samplesexample/jmstofile/CamelJmsToFileSampleCamelJmsToFileExample.java} |
In normal use, an external system would be firing messages or events into directly into Camel through one if its Components or Containers but we are going to use the CamelClient which is a really nice an easy way for testing your configuration:
Wiki Markup |
---|
{snippet:id=e4|lang=java|url=activemq/camel/trunk/examples/camel-egexample-jms-file/src/main/java/org/apache/camel/samplesexample/jmstofile/CamelJmsToFileSampleCamelJmsToFileExample.java} |
Next you must start the camel context. If you are using Spring to configure the camel context this is automatically done for you; though if you are using a pure Java approach then you just need to call the start() method
...
Wiki Markup |
---|
{snippet:id=e5|lang=java|url=activemq/camel/trunk/examples/camel-egexample-jms-file/src/main/java/org/apache/camel/samplesexample/jmstofile/CamelJmsToFileSampleCamelJmsToFileExample.java} |
What happens ?
From the CamelClient - we send objects (in this case text) into the CamelContext to the Component test-jms:queue:test.queue. These text objects will be converted automatically into JMS Messages and posted to a JMS Queue named test.queue. When we set up the Route, we configured the FileComponent to listen of the test.queue.
...