Instant Apache ServiceMix How-to [Instant] — Save 50%
Learn to create simple ServiceMix-based integration solutions using short, practical, hands-on recipes with this book and ebook
Usually, for practical purposes, we connect to the embedded Active MQ broker coming with ServiceMix out of the box. In real-world, however, you would probably need to connect to the standalone JMS broker. This article by Henryk Konsek, author of Instant Apache ServiceMix How-to,will teach how you can in the real world connect to the standalone JMS broker.
(For more resources related to this topic, see here.)
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...
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).
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.
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:
<property name="brokerURL" value="tcp://192.168.1.1:61616"/>
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.
This article explained, with examples, how you can in the real world connect to the standalone JMS broker.
Resources for Article :
- Using the OSGi Bundle Repository in OSGi and Apache Felix 3.0 [Article]
- Getting Started with Bookshelf Project in Apache Felix [Article]
- Geronimo Architecture: Part 2 [Article]
|Learn to create simple ServiceMix-based integration solutions using short, practical, hands-on recipes with this book and ebook|
eBook Price: $19.99
About the Author :
Henryk Konsek is a software engineer who has been working with Java-related technologies for six years. He is the committer for the Apache Camel project. His area of expertise is middleware and integration technologies. In his spare time Henryk enjoys riding downhill bikes. He is a dedicated father of two lovely daughters and husband to their awesome mom.