Book Image

Instant Apache ServiceMix How-to

By : Henryk Konsek
Book Image

Instant Apache ServiceMix How-to

By: Henryk Konsek

Overview of this book

<p>Creating reliable integration solution can be easy if you choose the right tools for the job. Apache Camel and ServiceMix are the leading integration technologies dedicated to dealing with the complexity of the messaging solutions. Learn how to efficiently integrate multiple systems with bleeding edge open source Apache software.</p> <p>"Instant Apache ServiceMix How-to" is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises that will help you take advantage of the real power that is behind the leading Apache integration stack.</p> <p>This book guides the reader in how to install ServiceMix and how to get it up and running. It will take you through a number of practical recipes – starting with the basic commands of Apache Karaf container and ending with the deployment of JMS and web service solutions.</p>
Table of Contents (7 chapters)

Routing to the embedded ActiveMQ broker (Should know)


One of the fundamental integration technologies in the Java world is JMS (Java Message Servi ce). While ServiceMix can connect to any JMS-compliant messaging system, this recipe demonstrates how to connect to the Apache ActiveMQ message broker.

Getting started

ServiceMix comes with an embedded ActiveMQ JMS broker that listens to the client connections on the port 61616. In order to use the embedded broker, you don't have to perform any additional administrative activities. The embedded ActiveMQ broker distributed out of the box with ServiceMix is configured with default settings and is ready to be used.

How to do it...

  1. Create a new Camel routing Maven project (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 a new Camel routing rule that produces to or consumes from the Camel ActiveMQ component with the default configuration.

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

How it works...

ServiceMix starts the embedded AcvtiveMQ broker on port 61616. This is also the default port of the Camel ActiveMQ component. This basically means that when you deploy to your Camel route, similar to the one presented here, Camel will automatically connect to the embedded ActiveMQ broker instance:

<camel:route>
<camel:from uri="timer://fireJmsMessage?period=5000"/>
<camel:to uri="activemq:myQueue"/>
</camel:route>

Since Camel ActiveMQ with the default configuration also listens on the same port (and on localhost loopback address), it will by default connect to the ActiveMQ instance embedded in ServiceMix.

In the preceding example, we created the Camel route that sends message to the embedded ActiveMQ broker's queue named myQueue every five seconds.

There's more...

ActiveMQ itself is a comprehensive and advanced messaging solution. It is possible to configure both your broker and client component (that is, the Camel endpoint) with a variety of parameters and options. This section will describe some of them, but remember that there is much more available out there.

Queues on demand

You may be wondering if it is necessary to create the myQueue queue from the preceding example. Fortunately ActiveMQ will create the queue for us as soon as it will receive the first message addressed to the latter queue. We say that the queue is created on demand.

Changing the ActiveMQ port

If, for some reason, you need to change the default port used by the embedded ActiveMQ broker (61616), just change the value of the activemq.port property in SERVICEMIX_HOME/etc/system.properties. Remember that you also need to change the port in the component configuration of your Camel routes. Refer to the Camel ActiveMQ component documentation at http://camel.apache.org/activemq.html for more details.

ActiveMQ reading

If you want to learn more about ActiveMQ itself, we recommend the excellent book from Manning Publishing, ActiveMQ in Action (http://www.manning.com/snyder), written by the topic experts Bruce Snyder, Dejan Bosanac, and Rob Davies. You can also visit the project Apache site at http://activemq.apache.org, where you can find the latest news regarding ActiveMQ.