Chapter 8. ActiveMQ Brokers and Clusters

Abstract

Fabric provides predefined profiles for deploying a single (unclustered) broker and, in addition, you can use the powerful fabric:mq-create command to create and deploy clusters of brokers.

8.1. Creating a Single Broker Instance

MQ profiles

The following profiles are important for creating broker instances:
mq-base
An abstract profile, which defines some important properties and resources for the broker, but should never be used directly to instantiate a broker.
mq-default
A basic single broker, which inherits most of its properties from the mq-base profile.
To examine the properties defined in these profiles, you can invoke the fabric:profile-display command, as follows:
JBossFuse:karaf@root> fabric:profile-display mq-default
...
JBossFuse:karaf@root> fabric:profile-display mq-base
...

Creating a new broker instance

A Fuse MQ broker is a Karaf container instance running a message broker profile. The profile defines the broker dependencies (through features) and the configuration for the broker. The simplest approach to creating a new broker is to use the provided mq-default profile.
For example, to create a new mq-default broker instance called broker1, enter the following console command:
JBossFuse:karaf@root> fabric:container-create-child --profile mq-default root broker1
Creating new instance on SSH port 8102 and RMI ports 1100/44445 at: 
   /Users/jdoe/Downloads/jboss-fuse-6.3.0-254/instances/broker1
The following containers have been created successfully:
    Container: broker1.
This command creates a new container called broker1 with a broker of the same name running on it.

fabric:mq-create command

The fabric:mq-create command provides a shortcut to creating a broker, but with more flexibility, because it also creates a new profile. To create a new broker instance called brokerx using fabric:mq-create, enter the following console command:
JBossFuse:karaf@root> fabric:mq-create --create-container broker --replicas 1 brokerx
MQ profile mq-broker-default.brokerx ready
Just like the basic fabric:container-create-child command, fabric:mq-create creates a container called broker1 and runs a broker instance on it. There are some differences, however:
  • The new broker1 container is implicitly created as a child of the current container,
  • The new broker has its own profile, mq-broker-default.brokerx, which is based on the mq-base profile template,
  • It is possible to edit the mq-broker-default.brokerx profile, to customize the configuration of this new broker.
  • The --replicas option lets you specify the number of master/slave broker replicas (for more details, see Section 8.3.2, “Master-Slave Cluster”). In this example, we specify one replica (the default is two).
Note
The new profile gets the name mq-broker-Group.BrokerName by default. If you want the profile to have the same name as the broker (which was the default in JBoss Fuse version 6.0), you can specify the profile name explicitly using the --profile option.
Important
The new broker is created with SSL enabled by default. The initial certificates and passwords created by default are not secure, however, and must be replaced by custom certificates and passwords. See the section called “Customizing the SSL keystore.jks and truststore.jks file” for details of how to do this.

Starting a broker on an existing container

The fabric:mq-create command can be used to deploy brokers on existing containers. Consider the following example, which creates a new Fuse MQ broker in two steps:
JBossFuse:karaf@root> fabric:container-create-child root broker1
Creating new instance on SSH port 8102 and RMI ports 1100/44445 at: 
    /Users/jdoe/Downloads/jboss-fuse-6.3.0-254/instances/broker1
The following containers have been created successfully:
    broker1.

JBossFuse:karaf@root> fabric:mq-create --assign-container broker1 brokerx
MQ profile mq-broker-default.brokerx ready
The preceding example firstly creates a default child container, and then creates and deploys the new mq-broker-default.brokerx profile to the container, by invoking fabric:mq-create with the --assign-container option. Of course, instead of deploying to a local child container (as in this example), we could assign the broker to an SSH container.

Broker groups

Brokers created using the fabric:mq-create command are always registered with a specific broker group. If you do not specify the group name explicitly at the time you create the broker, the broker gets registered with the default group by default.
If you like, you can specify the group name explicitly using the --group option of the fabric:mq-create command. For example, to create a new broker that registers with the west-coast group, enter the following console command:
JBossFuse:karaf@root> fabric:mq-create --create-container broker --replicas 1 --group west-coast brokery
MQ profile mq-broker-west-coast.brokery ready
If the west-coast group does not exist prior to running this command, it is automatically created by Fabric. Broker groups are important for defining clusters of brokers, providing the underlying mechanism for creating load-balancing clusters and master-slave clusters. For details, see Section 8.3, “Topologies”.