New ActiveMQ failover and clustering goodies

For the last two weeks I’ve been working on some interesting use cases for the good ol’ failover transport. I finally have some time at my hands, so here’s a brief recap of what’s coming in 5.6 release in this area.

First there’s a new feature, called Priority Backup. It’s described in details here, but in a nutshell it provides you with the mechanism of prioritizing your failover urls and keep your clients connected to them as soon as they are available. The most obvious use case for this is to keep your clients connected to the broker in local data center whenever you can. By doing this, you can both have better performances and stability of your clients, but also save on your bandwidth bills.

Another improvement is coming for automatic broker cluster feature. Although this feature is not new, I spent some time hardening it and thought to share some more insight in how (and when) to use it in your projects.

In search of high availability, people often default to master-slave architecture. This makes sense in most use cases, but if your flow is purely non-persistent you can probably come up with more optimal architecture. Instead of having one broker at the time handling all your load, and other one just waiting for it to fail, you’ll get more efficient system with some kind of active-active configuration where (possibly multiple) brokers share the load all the time. Ideally clients would be evenly distributed and would rebalance if anything changes. Brokers don’t need to share any messages as clients are distributed and messages are non-persistent so they will be lost if broker fails. So can you achieve this kind of architecture with ActiveMQ?

Sure you do. That’s where automatic rebalance and clustering shines. First of all, brokers should be networked but only so they can exchange information on their availability. They shouldn’t exchange the messages (but of course can if your use case needs it). In 5.6 you do that with pure static networks, using configuration like

<networkConnector uri="static:(tcp://host)" staticBridge="true"/>

So now imagine three brokers A,B and C forming a full mesh. In addition every broker uses rebalance options on their transport connectors

<transportConnector name="openwire" uri="tcp://localhost:61616"
                    updateClusterClients="true" updateClusterClientsOnRemove="true"
                    rebalanceClusterClients="true"
/>

All that is left for the client to do is connect to one of the brokers it knows like

failover:(brokerA)

and the broker will fill it with all information on other brokers in the cluster and whether it should reconnect to one of them or not. So having a large number of clients connecting like this, very soon they’ll rebalance over available brokers. You can stop one of the brokers in the cluster for updates and clients will rebalance over remaining ones. You can even add a new broker to the cluster and everything will get rebalanced without any need for you to touch your clients.

So, basically in this way you have both load balancing and high availability for your non-persistent messages. Additionally, your clients are automatically updated with all information they need, and no manual intervention is needed.

Although the basic support for clustering was there since 5.4, I did some more hardening and better rebalancing, so it’s coming in the Apache ActiveMQ 5.6 (and the next Fuse 5.5.1) release. Also, there are some more great stuff regarding broker clustering coming soon, so stay tuned and happy messaging.

7 comments

  1. I cannot make both Priority Backup and automatic rebalance & clustering work at the same time.

    I want rebalance only for brokers in the local datacenter but I want clients to failover to the other datacenter if all the local fail.

    If you enable updateClusterClients, clients don’t pay attention to the priorityBack up feature and they connect to any broker in the cluster. But when you have multiple datacenter this is not something you want.

  2. Please provide a demo code if possible on github with persistent messages. How do we code/configure for persistent messages and pure static networks?

    Also, is there a topology or architecture diagram available for this scenario?

Comments are closed.