Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

ActiveMQ Integration in Mule and Performance Tuning Techniques

DZone's Guide to

ActiveMQ Integration in Mule and Performance Tuning Techniques

Learn how to integrate the ActiveMQ message broker with Mule, plus some tips on tuning ActiveMQ performance for better speed and efficiency.

· Integration Zone ·
Free Resource

The new Gartner Critical Capabilities report explains how APIs and microservices enable digital leaders to deliver better B2B, open banking and mobile projects.

ActiveMQ is one of the popular open source messaging providers. Mule is one of the most famous integration providers, which provides an ESB feature and framework to expose/create API mechanisms. Mule provides a connector to integrate easily with ActiveMQ and supports JMS 1.1 and J2SE 1.4 specifications.

Here, we will talk about the basic integration of ActiveMQ with Mule and performance tuning techniques. ActiveMQ configuration needs to be done using the JMS connector, which comes default in AnyPoint Studio.

Integration Steps

Drag and drop the JMS connector from the design palette in Anypoint Studio.

Image title

For connector configuration, use <jms:activemq-connector> or <jms:activemq-xa-connector> (to support XA transactions), like so:

<jms:activemq-connector name="jmsConnector"
                          brokerURL="tcp://localhost:61616"/>
  <jms:activemq-xa-connector name="jmsXAConnector"
                             brokerURL="tcp://localhost:61616"/>

Active MQ Connector Reference:

Click on "Connector configuration" and add the ActiveMQ information.

Image title

Refer to the documentation for more information on connector configuration.

Performance Tuning

When ActiveMQ message producer sends a non-persistent message (async publishing), it's dispatched asynchronously (fire then forget), but in the case of persistent messages, the publisher will block until it gets a notification that message has been processed by the broker.

Messages are dispatched with the delivery mode set to be persistent by default, so if you are sending messages on a topic, the publisher will block by default (even if there are no durable subscribers on the topic) until the broker has returned a notification.

So if you looking for good performance with topic messages, either set the delivery mode on the publisher to be non-persistent or set the "useAsyncsend" property on the ActiveMQ ConnectionFactory.

What Is the Preferred Pre-Fetch Size for Consumers?

ActiveMQ has the capability to push as many messages to the consumer as fast as possible, where they will be queued for processing by an ActiveMQ session. Here, pre-fetch configuration is very important based on the consumer.

The maximum number of messages that ActiveMQ will push to a consumer without the consumer processing a message is set by the pre-fetch size. It's very important to define the correct pre-fetch size for consumers, since during large volumes of transactions, there is a huge chance of messages piling up, which creates system failovers.

Default values - For Consumer type - queue - 1000 , queue- browser - 500, topic - 32767, durable topic - 1000.

Maven Integration

Mule supports Maven integration. Maven allows you to run performance tests easily using the Maven command line, or run tests automatically as part of your continuous integration.

Maven repo to run:


    <plugin>
    <groupId>org.apache.activemq.tooling</groupId>
    <artifactId>activemq-perf-maven-plugin</artifactId>
    <version>${activemq-version}</version>
    </plugin>

Maven Goals:

  • activemq-perf:consumer - Starts the consumer's performance testing. The generated report file can be found in the directory specified in the parameter "sysTest.reportDir."

  • activemq-perf:producer- Starts the producer's performance testing. The generated report file can be found in the directory specified in the parameter "sysTest.reportDir."

  • activemq-perf:broker - Starts broker using the activemq configuration file located in "src\main\resources\broker-conf" where the default config is activemq.xml.

Parameters: 

  • -DconfigType - specifies the type of configuration to use. Its value must be one of the -DconfigFile - path to config file other than those in "src\..\broker-config".e.g -DconfigFile=c:\dir\activemq.xml).

File-based persistence: Apache ActiveMQ supports a file-based persistence store that can be used to increase throughput for persistent messages. As part of configuration, set pre-acknowledge to true. With pre-acknowledge mode, messages are acknowledged before they are sent to the client; this will reduce the amount of acknowledgment traffic in the flow.  Disable the persistence if you don't need it; you get a good performance boost by disabling persistence.

The new Gartner Critical Capabilities for Full Lifecycle API Management report shows how CA Technologies helps digital leaders with their B2B, open banking, and mobile initiatives. Get your copy from CA Technologies.

Topics:
mule ,activemq ,integration ,performance tuning

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}