3 min read

(For more resources related to this topic, see here.)

Getting ready

In this recipe, we will assume that you have a standalone ActiveMQ broker installed, started, and is operational. To make the examples as simple as possible, we will also assume that the broker is exposed via the tcp://192.168.1.1:61616 TCP transport.

How to do it…

  1. Create a new Camel routing project using Maven (if you don’t know how to do it, refer to the Creating and deploying a new Camel route (Must know) recipe).

  2. In the camel-context.xml file, add the new Camel routing rule that produces to or consumes from the Camel ActiveMQ component connected to the standalone router.

  3. Build and deploy the routing module to your ServiceMix instance (if you don’t know how to do it, refer to the Creating and deploying a new Camel route (Must know) recipe).

How it works…

Connecting to the external ActiveMQ broker is very similar to working with the embedded ActiveMQ broker provided with ServiceMix. The only difference is that instead of using the default settings of the Camel ActiveMQ component, you need to configure your route to consume from (or produce to) the standalone ActiveMQ broker.

The Camel ActiveMQ component can be configured in many ways. One of the possible solutions is to register the component manually in the Spring application context. The following example demonstrates how to register and configure an ActiveMQ component in the Spring context:

<camel:camelContext >
<camel:route>
<camel:from uri="timer:jmsMessageTrigger?period=5000"/>
<camel:to uri="activemq:myQueue"/>
</camel:route>
</camel:camelContext>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://192.168.1.1:61616"/>
</bean>

There’s more…

You can connect to many types of messaging brokers with ServiceMix. The Camel routing engine allows ServiceMix to integrate with any JMS-compatible messaging solutions. Camel also comes with support for some non-JMS messaging systems (such as XMPP, AMPQ, or Amazon SQS). The following is some additional information regarding the messaging support in ServiceMix.

Generic JMS connectivity

If you need to connect to a JMS broker other than ActiveMQ, use the Camel JMS component instead of the ActiveMQ component. The camel JMS component (http://camel.apache.org/jms.html) can be used to connect to any JMS-compatible messaging server (including ActiveMQ). Keep in mind, however, that if you connect to the ActiveMQ broker, it is better to stick to the dedicated ActiveMQ component, as the latter is optimized for the Apache message broker. As a result, you can expect easier configuration and slighter better performance when using a dedicated ActiveMQ component.

ActiveMQ connection pooling

A common mistake regarding the usage of JMS is to open a new client connection for each message sent to the broker. Creating a new connection to the broker is an expensive operation. The typical solution to optimize the JMS connection management is to reuse the already opened ones. This approach is called “Connection pooling”, ActiveMQ comes with the connection factory that supports connection pooling; it is named org.apache.activemq. pool.PooledConnectionFactory. You should remember it whenever you configure your ActiveMQ connection in Camel.

Summary

This article explained, with examples, how you can in the real world connect to the standalone JMS broker.

Resources for Article :


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here