Skip to content

Commit 4102638

Browse files
authored
Merge pull request #5 from jbertram/andy-master
Formatting, grammar, etc.
2 parents b480848 + adcbb3a commit 4102638

File tree

3 files changed

+225
-204
lines changed

3 files changed

+225
-204
lines changed

demos/broker/clustering/README.md

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
## Networks of Brokers in AMQ7 Broker (Clustering)
1+
## Networks of Brokers in AMQ 7 Broker (Clustering)
22

3-
This worksheet covers clustering AMQ7 Brokers.
4-
By the end of this you should know:
3+
This worksheet covers clustering AMQ 7 brokers. By the end of this you should know:
54

6-
1. Clustering concepts of AMQ7
5+
1. Clustering concepts of AMQ 7
76
* Discovery
87
* Cluster bridges
98
* Routing of messages
@@ -12,18 +11,18 @@ By the end of this you should know:
1211

1312
2. How to configure Clustering
1413
* Configuring Discovery
15-
* Configuring A cluster
14+
* Configuring a cluster
1615
* Configuring Load Balancing
1716

1817

19-
### AMQ7 Clustering Concepts
18+
### AMQ 7 Clustering Concepts
2019

21-
Multiple instances of AMQ7 Brokers can be grouped together to share message processing load.
22-
Each Broker manages its own messages and connections and is connected to other brokers with
23-
"cluster bridges" that are used to send Topology information, such as queues and consumers,
20+
Multiple instances of AMQ 7 brokers can be grouped together to share message processing load.
21+
Each broker manages its own messages and connections and is connected to other brokers with
22+
"cluster bridges" that are used to send topology information, such as queues and consumers,
2423
as well as load balancing messages.
2524

26-
### Simple 2 node cluster
25+
### Simple 2-node cluster
2726

2827
Lets create 2 clustered brokers using the CLI, firstly, since AMQ 7 uses UDP for discovery
2928
you will need to ensure that a loopback address is created, this will allow UDP to work on the same machine.
@@ -37,21 +36,26 @@ On a Mac this will be something like
3736
3837
Now lets create a cluster of 2 brokers by running the CLI commands
3938

40-
(A_MQ_Install_Dir)/bin/artemis create --user admin --password password --role admin --allow-anonymous y --clustered --host 127.0.0.1 --cluster-user clusterUser --cluster-password clusterPassword --max-hops 1 broker1
39+
```
40+
$ <AMQ_HOME>/bin/artemis create --user admin --password password --role admin --allow-anonymous y --clustered --host 127.0.0.1 --cluster-user clusterUser --cluster-password clusterPassword --max-hops 1 ../instances/clusteredbroker1
41+
```
4142

4243
and
4344

44-
(A_MQ_Install_Dir)/bin/artemis create --user admin --password password --role admin --allow-anonymous y --clustered --host 127.0.0.1 --cluster-user clusterUser --cluster-password clusterPassword --max-hops 1 --port-offset 100 broker2
45+
```
46+
$ <AMQ_HOME>/bin/artemis create --user admin --password password --role admin --allow-anonymous y --clustered --host 127.0.0.1 --cluster-user clusterUser --cluster-password clusterPassword --max-hops 1 --port-offset 100 ../instances/clusteredbroker2
47+
```
4548

46-
Now start both brokers using the run command, for instance
49+
Now start *both* brokers using the `run` command for each one, for instance:
4750

48-
"(Broker1_Home)/broker1/bin/artemis" run
51+
```
52+
$ <AMQ_INSTANCE>/bin/artemis run
53+
```
4954
50-
What you should see is each Broker discovering each other and connection a cluster bridge,
51-
you should see a log message on each Broker showing this, something like:
55+
What you should see is each broker discovering each other and creating a cluster bridge. You should see a log message on each broker showing this, something like:
5256

5357
```bash
54-
12:42:35,488 INFO [org.apache.activemq.artemis.core.server] AMQ221027: Bridge ClusterConnectionBridge@1d90c678 [name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583], temp=false]@60ff2ab7 targetConnector=ServerLocatorImpl (identity=(Cluster-connection-bridge::ClusterConnectionBridge@1d90c678 [name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583], temp=false]@60ff2ab7 targetConnector=ServerLocatorImpl [initialConnectors=[TransportConfiguration(name=artemis, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61716&host=127-0-0-1], discoveryGroupConfiguration=null]]::ClusterConnectionImpl@943454742[nodeUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583, connector=TransportConfiguration(name=artemis, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=127-0-0-1, address=, server=ActiveMQServerImpl::serverUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583])) [initialConnectors=[TransportConfiguration(name=artemis, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61716&host=127-0-0-1], discoveryGroupConfiguration=null]] is connected
58+
INFO [org.apache.activemq.artemis.core.server] AMQ221027: Bridge ClusterConnectionBridge@1d90c678 [name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583], temp=false]@60ff2ab7 targetConnector=ServerLocatorImpl (identity=(Cluster-connection-bridge::ClusterConnectionBridge@1d90c678 [name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.8d25b0ff-55ad-11e7-bfb2-e8b1fc559583, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583], temp=false]@60ff2ab7 targetConnector=ServerLocatorImpl [initialConnectors=[TransportConfiguration(name=artemis, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61716&host=127-0-0-1], discoveryGroupConfiguration=null]]::ClusterConnectionImpl@943454742[nodeUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583, connector=TransportConfiguration(name=artemis, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=127-0-0-1, address=, server=ActiveMQServerImpl::serverUUID=86fab59a-55ad-11e7-ae52-e8b1fc559583])) [initialConnectors=[TransportConfiguration(name=artemis, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61716&host=127-0-0-1], discoveryGroupConfiguration=null]] is connected
5559
```
5660

5761
You can also log into the HawtIO Console by going to 'http://localhost:8161/hawtio' and click on the
@@ -65,19 +69,18 @@ We now have a cluster of 2 brokers, lets look in more detail at the configuratio
6569

6670
#### Discovery
6771

68-
When a Clustered Broker is started the first thing it does is try to discover another Broker in the cluster.
69-
It will keep doing this until it finds a Broker at which time it will try to create a Cluster Bridge to it.
70-
By default the Broker will use UDP to broadcast its location and to also discover other Brokers.
71-
72+
When a clustered broker is started the first thing it does is try to discover another broker in the cluster.
73+
It will keep doing this until it finds a broker at which time it will try to create a cluster bridge to it.
74+
By default the broker will use UDP multicast to broadcast its location and to also discover other brokers.
7275

73-
The first thing to notice in the configuration file is the connector config that will be broadcast to other Brokers, this
76+
The first thing to notice in the configuration file is the connector config that will be broadcast to other brokers, this
7477
looks like:
7578

7679
```xml
7780
<connector name="artemis">tcp://127.0.0.1:61616</connector>
7881
```
7982

80-
A Broadcast Group then defines how a Broker broadcasts the connector info, this looks something like:
83+
A `broadcast-group` then defines how a broker broadcasts the connector info, this looks something like:
8184

8285
```xml
8386
<broadcast-group name="bg-group1">
@@ -89,9 +92,9 @@ A Broadcast Group then defines how a Broker broadcasts the connector info, this
8992

9093
```
9194

92-
This configuration will broadcast the 'artemis' connector info over the UDP address 231.7.7.7:9876 every 5 secosnds.
95+
This configuration will broadcast the 'artemis' connector info over the multicast address 231.7.7.7:9876 every 5 secosnds.
9396

94-
Now a Broker needs to be able discover the above broadcast, this is done via a discovery group. This looks like:
97+
Now a broker needs to be able discover the above broadcast, this is done via a `discovery-group`. This looks like:
9598

9699
```xml
97100
<discovery-group name="dg-group1">
@@ -101,7 +104,7 @@ Now a Broker needs to be able discover the above broadcast, this is done via a d
101104
</discovery-group>
102105
```
103106

104-
This configuration doesn't do anything by itself but is referenced by a cluster connection configuration, which looks like:
107+
This configuration doesn't do anything by itself but is referenced by a `cluster-connection`, which looks like:
105108

106109
```xml
107110
<cluster-connection name="my-cluster">
@@ -112,62 +115,61 @@ This configuration doesn't do anything by itself but is referenced by a cluster
112115
</cluster-connection>
113116
```
114117

115-
You can see that the 'discovery-group-ref' references a discovery group, once started the Broker will listen on
116-
the UDP address 231.7.7.7:9876 for other Brokers broadcasting.
118+
You can see that the `discovery-group-ref` references a discovery group. Once started, the broker will listen on
119+
the multicast address 231.7.7.7:9876 for other brokers broadcasting.
117120

118-
Once the Broker has discovered a target broker it will try to create a Cluster Bridge to that Broker, we refer to this as initial discovery.
119-
Once initial discovery is complete all other discovery is done over the Cluster Bridge, in a 2 node cluster it would happen
121+
Once the broker has discovered a target broker it will try to create a cluster bridge to that broker. We refer to this as *initial discovery*.
122+
Once initial discovery is complete all other discovery is done over the cluster bridge itself. In a 2 node cluster it would happen
120123
like so:
121124

122-
1. The source Broker sends its full Topology over the cluster bridge to its target Broker, This includes a list of Brokers it
123-
is aware of , including itself configured by the connector-ref in the cluster-connection config, and a list of queues and consumers.
124-
2. The target broker then uses the list of Brokers to create its own cluster bridges, in this case back to the source Broker.
125-
3. The target Broker then sends its own Topology over its cluster bridges.
126-
4. Both Broker create any queues based on the Topology received.
125+
1. The source broker sends its full topology over the cluster bridge to its target broker. This includes a list of brokers it
126+
is aware of (including itself configured by the `connector-ref` in the `cluster-connection`) and a list of queues and consumers.
127+
2. The target broker then uses the list of brokers to create its own cluster bridges (in this case back to the source broker).
128+
3. The target broker then sends its own topology over its cluster bridges.
129+
4. Both brokers create any queues based on the topology received.
127130

128131

129-
##### Discovery without UDP (Static Connectors), Optional
132+
##### Discovery without UDP multicast (Static Connectors), Optional
130133

131-
If UDP is not available then Brokers can be statically configured. This is done purely through connectors.
134+
If UDP multicast is not available then brokers can be *statically* configured. This is done purely through connectors.
132135

133-
Lets update broker1 and 2 to use static connectors.
136+
Lets update brokers 1 and 2 to use static connectors.
134137

135138
Firstly remove both the broadcast and discovery groups configuration completely.
136139

137140
```xml
138-
<!-- remove the following lines -->
139-
<broadcast-groups>
140-
<broadcast-group name="bg-group1">
141-
<group-address>231.7.7.7</group-address>
142-
<group-port>9876</group-port>
143-
<broadcast-period>5000</broadcast-period>
144-
<connector-ref>artemis</connector-ref>
145-
</broadcast-group>
146-
</broadcast-groups>
147-
148-
<discovery-groups>
149-
<discovery-group name="dg-group1">
150-
<group-address>231.7.7.7</group-address>
151-
<group-port>9876</group-port>
152-
<refresh-timeout>10000</refresh-timeout>
153-
</discovery-group>
154-
</discovery-groups>
155-
141+
<!-- remove the following lines -->
142+
<broadcast-groups>
143+
<broadcast-group name="bg-group1">
144+
<group-address>231.7.7.7</group-address>
145+
<group-port>9876</group-port>
146+
<broadcast-period>5000</broadcast-period>
147+
<connector-ref>artemis</connector-ref>
148+
</broadcast-group>
149+
</broadcast-groups>
150+
151+
<discovery-groups>
152+
<discovery-group name="dg-group1">
153+
<group-address>231.7.7.7</group-address>
154+
<group-port>9876</group-port>
155+
<refresh-timeout>10000</refresh-timeout>
156+
</discovery-group>
157+
</discovery-groups>
156158
```
157159

158-
Then add a connector that points to the other broker, so on broker 1 it would look like:
160+
Then on each broker add a connector that points to the *other* broker. So on broker 1 it would look like:
159161

160162
```xml
161163
<connector name="discovery-connector">tcp://127.0.0.1:61716</connector>
162164
```
163165

164-
broker 2 would look like
166+
And on broker 2 it would look like:
165167

166168
```xml
167169
<connector name="discovery-connector">tcp://127.0.0.1:61616</connector>
168170
```
169171

170-
Lastly remove the discovery-group-ref from the cluster-connection elemet and replace it with the following:
172+
Lastly remove the `discovery-group-ref` from the `cluster-connection` on both brokers and replace it with the following:
171173

172174
```xml
173175
<static-connectors>
@@ -177,46 +179,47 @@ Lastly remove the discovery-group-ref from the cluster-connection elemet and rep
177179

178180
Now if you restart the brokers you will again see them form a cluster.
179181

180-
> Note
182+
> ##### Note
181183
> The static connectors list can contain all the possible brokers in the cluster,
182184
> however it only needs 1 to be available to connect to.
183185
184186

185-
#### Client Side load balancing
187+
#### Client-side Connection Load Balancing
186188

187-
Client Side balancing is the ability to spread connections across multiple brokers,
189+
Client-side connection load balancing is the ability of a client to spread connections across multiple brokers,
188190
currently only the core JMS client supports this. This is done via load balancing policies configured on the
189-
Connection Factory. If using JNDI the `jndi.properties`would look like:
191+
connection factory via the `loadBalancingPolicyClassName` URL property. If using JNDI the `jndi.properties` would look like:
190192

191-
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
192-
connection.myConnectionFactory=tcp://localhost:61616?loadBalancingPolicyClassName=org.apache.activemq.artemis.api.core.client.loadbalance.RandomConnectionLoadBalancingPolicy
193+
```properties
194+
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
195+
connection.myConnectionFactory=tcp://localhost:61616?loadBalancingPolicyClassName=org.apache.activemq.artemis.api.core.client.loadbalance.RandomConnectionLoadBalancingPolicy
196+
```
193197

194198
The available policies are
195199

196-
- Round Robin.
197-
- Random.
198-
- Random Sticky.
199-
- First Element.
200+
* Round Robin (`org.apache.activemq.artemis.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy`).
201+
* Random (`org.apache.activemq.artemis.api.core.client.loadbalance.RandomConnectionLoadBalancingPolicy`).
202+
* Random Sticky (`org.apache.activemq.artemis.api.core.client.loadbalance.RandomStickyConnectionLoadBalancingPolicy`).
203+
* First Element (`org.apache.activemq.artemis.api.core.client.loadbalance.FirstElementConnectionLoadBalancingPolicy`).
200204

201-
You can also implement your own policy by implementing an interface
205+
All of these classes ship in the `artemis-core-client` JAR. You can also implement your own policy by implementing the `org.apache.activemq.artemis.api.core.client.loadbalance.ConnectionLoadBalancingPolicy` interface.
202206

203207
#### Message Load Balancing
204208

205-
The Message Load balancing Policy configures how messages are load balanced around the cluster.
209+
The message load balancing policy configures how messages are load balanced around the cluster *by the server*.
206210
This is configured in the cluster-connection, like so.
207211

208212
```xml
209213
<message-load-balancing>ON_DEMAND</message-load-balancing>
210214
```
211215

212-
By default it is ON_DEMAND, which means that messages will be round robined around Brokers that have
213-
available consumers.
216+
By default it is ON_DEMAND, which means that messages will be round robined around Brokers that have available consumers.
214217

215-
> Note
218+
> ##### Note
216219
> Messages are routed at the point they arrive at the broker and before they arrive on a queue.
217220
> They will either route to a local queue or to a queue on another broker
218221
219-
We can test this using the cli, but firstly each broker needs to be stopped and the clustered queues configured,
222+
We can test this using the CLI, but firstly each broker needs to be stopped and the clustered queues configured,
220223
add the following queue to each broker:
221224

222225
```xml
@@ -232,20 +235,20 @@ And then restart the brokers.
232235
firstly lets send 20 messages to broker 1:
233236

234237
```bash
235-
${ARTEMIS_HOME}/bin/artemis producer --url tcp://localhost:61616 --message-count 20 --destination queue://myQueue
238+
$ <AMQ_HOME>/bin/artemis producer --url tcp://localhost:61616 --message-count 20 --destination queue://myQueue
236239
```
237240

238241
Since there are no consumers these will simple be delivered to the local queue on broker 1. We can test this by trying
239242
to consume from broker 2:
240243

241244
```bash
242-
${ARTEMIS_HOME}/bin/artemis consumer --url tcp://localhost:61716 --destination queue://myQueue --message-count 10
245+
$ <AMQ_HOME>/bin/artemis consumer --url tcp://localhost:61716 --destination queue://myQueue --message-count 10
243246
```
244247

245248
This should just hang without receiving any message. Now try broker 1
246249

247250
```bash
248-
${ARTEMIS_HOME}/bin/artemis consumer --url tcp://localhost:61616 --destination queue://myQueue --message-count 20
251+
$ <AMQ_HOME>/bin/artemis consumer --url tcp://localhost:61616 --destination queue://myQueue --message-count 20
249252
```
250253

251254
The client will receive all 20 message.
@@ -260,4 +263,4 @@ Now try the first part of this again, but this time setting the load balancing t
260263
<message-load-balancing>STRICT</message-load-balancing>
261264
```
262265

263-
This time the messages are load balanced even tho no consumer exist.
266+
This time the messages are load balanced even though no consumer exist.

0 commit comments

Comments
 (0)