This component is based on JMS Component and uses Spring's JMS support for declarative transactions, using Spring's
To use this component make sure you have the
Transacted and caching
Where destinationName is an ActiveMQ queue or topic name. By default, the destinationName is interpreted as a queue name. For example, to connect to the queue,
You can include the optional
To connect to a topic, you must include the
See Options on the JMS component as all these options also apply for this component.
Configuring the Connection Factory
Configuring the Connection Factory using Spring XML
You can configure the ActiveMQ broker URL on the ActiveMQComponent as follows
Using connection pooling
When sending to an ActiveMQ broker using Camel it's recommended to use a pooled connection factory to efficiently handle pooling of JMS connections, sessions and producers. This is documented on the ActiveMQ Spring Support page.
You can grab ActiveMQ's
And then setup the activemq Camel component as follows:
Notice the init and destroy methods on the pooled connection factory. This is important to ensure the connection pool is properly started and shutdown.
Important information about when using transactions
If you are using transactions then see more details at JMS. And remember to set
Invoking MessageListener POJOs in a Camel route
The ActiveMQ component also provides a helper Type Converter from a JMS MessageListener to a Processor. This means that the Bean component is capable of invoking any JMS MessageListener bean directly inside any route.
So for example you can create a MessageListener in JMS like this:
Then use it in your Camel route as follows
That is, you can reuse any of the Camel Components and easily integrate them into your JMS
Using ActiveMQ Destination Options
Available as of ActiveMQ 5.6
You can configure the Destination Options in the endpoint uri, using the "destination." prefix. For example to mark a consumer as exclusive, and set its prefetch size to 50, you can do as follows:
Consuming Advisory Messages
ActiveMQ can generate Advisory messages which are put in topics that you can consume. Such messages can help you send alerts in case you detect slow consumers or to build statistics (number of messages/produced per day, etc.) The following Spring DSL example shows you how to read messages from a topic.
The below route starts by reading the topic ActiveMQ.Advisory.Connection. To watch another topic, simply change the name according to the name provided in ActiveMQ Advisory Messages documentation. The parameter mapJmsMessage=false allows for converting the org.apache.activemq.command.ActiveMqMessage object from the jms queue. Next, the body received is converted into a String for the purposes of this example and a carriage return is added. Finally, the string is added to a file
If you consume a message on a queue, you should see the following files under the data/activemq folder :
and containing string:
Getting Component JAR
You will need this dependency