Tuesday December 13, 2016

Fast Messaging With Apache ActiveMQ Artemis

First, what is Apache ActiveMQ Artemis

Apache Artemis is a sub project of ActiveMQ, where we are developing a new broker using 100% asynchronous back end. Messages are through a fast Journal Storage or through its Paging System when messages are beyond the capacity of the memory.

It was based on the donation from HornetQ, but it has evolved a lot since it joined the Apache ActiveMQ community, both evolving as a software and as an open source community

You can do either very fast messaging without using transactions, or you can use its mature transaction API (XA or regular transactions)

On this blog entry here I will cover how you can send thousands of messages per second by sending them asynchronously. Since there are many users interested in not using a transaction at all these days.

This is a guide to how to make your producers and consumers fly with Artemis

Many users have been using message systems that will favor performance instead of full guarantees of writes.

This is something we have been doing for years with the Artemis codebase, including Artemis and previous versions of HornetQ.

This is a small tutorial to do such thing with Artemis, pretty simple and quite powerful.

This will make sender to be 100% asynchronous, So you never block the producer and you can easily make thousands messages / second.

Even still the guarantees are quite high as the message will be persisted at the journal within milliseconds.

So, here is how you do it:

  • Disable Block on Persistent Messages:

There are two ways you can do that:

I - Disable blockOnDurableSend through a property:

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();

II - Disable blockOnDurableSend through the URI for the connection Factory:

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616?blockOnDurableSend=false);

  • Send non Transactionally:

A transaction means a hard sync on the world. Make a round trip to the server and sync on disk.
If you send a regular Persistent Message, asynchronously, then you get a large throughput on your producers.

Here is a full example:
package org.apache.activemq.artemis.cli.commands.messages;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;

import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;

public class FastProducer {

   public static void main(String arg[]) {
      try {
         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616?blockOnDurableSend=false");
         Connection connection = factory.createConnection();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         Destination queue = ActiveMQDestination.createDestination("queue://TEST", ActiveMQDestination.QUEUE_TYPE);
         MessageProducer producer = session.createProducer(queue);

         long time = System.currentTimeMillis();

         for (int i = 0; i < 100000; i++) {
            producer.send(session.createTextMessage("hello guys"));

         System.out.println("Send message in " + (System.currentTimeMillis() - time) + " milliseconds");

      catch (Exception e) {


With this little example here I am able to send 100K messages in less than 2 seconds using my laptop.

Send message in 1772 milliseconds

And we are still improving things. Watch out for more improvements over the next month :)


Post a Comment:
  • HTML Syntax: NOT allowed



Hot Blogs (today's hits)

Tag Cloud