ActiveMQ ComponentThe ActiveMQ component allows messages to be sent to a JMS Queue or Topic or messages to be consumed from a JMS Queue or Topic using Apache ActiveMQ. 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 URI formatWhere 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 OptionsSee Options on the JMS component as all these options also apply for this component. Configuring the Connection FactoryThis test case shows how to add an ActiveMQComponent to the CamelContext using the Configuring the Connection Factory using Spring XMLYou can configure the ActiveMQ broker URL on the ActiveMQComponent as follows Using connection poolingWhen 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 The Invoking MessageListener POJOs in a Camel routeThe 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 OptionsAvailable 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 MessagesActiveMQ 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 : advisoryConnection-20100312.txt and containing string: Getting Component JARYou will need this dependency
ActiveMQ is an extension of the JMS component released with the ActiveMQ project. See Also |