Routing to an external ActiveMQ broker

Exclusive offer: get 50% off this eBook here
Instant Apache ServiceMix How-to [Instant]

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

$19.99    $10.00
by Henryk Konsek | June 2013 | Cookbooks Java Open Source

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.)

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 xmlns="http://camel.apache.org/schema/spring">
<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:


Instant Apache ServiceMix How-to [Instant] Learn to create simple ServiceMix-based integration solutions using short, practical, hands-on recipes with this book and ebook
Published: June 2013
eBook Price: $19.99
See more
Select your format and quantity:

About the Author :


Henryk Konsek

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.

Books From Packt


JBoss ESB Beginner’s Guide
JBoss ESB Beginner’s Guide

Service Oriented Java Business Integration
Service Oriented Java Business Integration

 Application Development for IBM WebSphere Process Server 7 and Enterprise Service Bus 7
Application Development for IBM WebSphere Process Server 7 and Enterprise Service Bus 7

 Java EE 6 Development with NetBeans 7
Java EE 6 Development with NetBeans 7

 Do more with SOA Integration: Best of Packt
Do more with SOA Integration: Best of Packt

Apache Maven 3 Cookbook
Apache Maven 3 Cookbook

Apache Solr 3 Enterprise Search Server
Apache Solr 3 Enterprise Search Server

 OSGi and Apache Felix 3.0 Beginner's Guide
Apache Maven 2 Effective Implementation


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
y
j
h
8
E
f
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software