JMS is used in many examples for other components as well. But we provide a few samples below to get started.
In the following sample we configure a route that receives JMS messages and routes the message to a POJO:
You can of course use any of the EIP patterns so the route can be context based. For example, here's how to filter an order topic for the big spenders:
from("jms:topic:OrdersTopic") .filter().method("myBean", "isGoldCustomer") .to("jms:queue:BigSpendersQueue");
In the sample below we poll a file folder and send the file content to a JMS topic.
As we want the content of the file as a
TextMessage instead of a
BytesMessage, we need to convert the body to a
from("file://orders") .convertBodyTo(String.class). .to("jms:topic:OrdersTopic");
The preceding examples use the Java DSL. Camel also supports Spring XML DSL. Here is the big spender sample using Spring DSL:
<route> <from uri="jms:topic:OrdersTopic"/> <filter> <method bean="myBean" method="isGoldCustomer"/> <to uri="jms:queue:BigSpendersQueue"/> </filter> </route>
JMS appears in many of the examples for other components and EIP patterns, as well in the online Apache Camel documentation. A recommended tutorial is this one that uses JMS but focuses on how well Spring Remoting and Camel work together Tutorial-JmsRemoting.