Setting up the Code
There is an JMS message to File example that ships as part of the camel distribution. Download the source ???
...
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=activemq/camel/trunk/camel-eg-jms-file/src/testmain/java/org/apache/camel/samples/jmstofile/CamelJmsToFileSample.java} |
...
Wiki Markup |
---|
{snippet:id=e2|lang=java|url=activemq/camel/trunk/camel-eg-jms-file/src/testmain/java/org/apache/camel/samples/jmstofile/CamelJmsToFileSample.java} |
...
Wiki Markup |
---|
{snippet:id=e3|lang=java|url=activemq/camel/trunk/camel-eg-jms-file/src/testmain/java/org/apache/camel/samples/jmstofile/CamelJmsToFileSample.java} |
In normal use, an external system would be firing messages or events into directly into Camel through one if its Components or Containers or through o 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/camel-eg-jms-file/src/main/java/org/apache/camel/samples/jmstofile/CamelJmsToFileSample.java} |
So after starting the CamelContext, we can fire some objects into camel:
Wiki Markup |
---|
{snippet:id=e5|lang=java|url=activemq/camel/trunk/camel-eg-jms-file/src/main/java/org/apache/camel/samples/jmstofile/CamelJmsToFileSample.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 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.
The File FileComponent will take messages of the Queue, and save them to a directory named test. Every message will be saved in a file that corresponds to its destination and message id.
Finally, we configured our own listener in the Route - to take notifications from the FileComponent and print them out as text.
Thats it!