Open ejlp12 opened 9 years ago
By default, JBoss A-MQ will start in interactive mode, which means it both starts the server, and displays the command Console. There are startup options to refine this, such as ./bin/amq
server to just start the server without the Console, and ./bin/amq
client to start just the Console that will connect to a locally running server.
Now that we have a running local JBoss A-MQ server, you have a whole new command Console to play with...
The JBoss A-MQ container supports an SSHD server that allows you to SSH into your running server to manage it. When you start up JBoss A-MQ, by default, it displays the Console for the instance you just started. You can also use a script to connect to other local and remote instances (check out <JBoss A-MQ Home>/bin/client --help
).
This Console supports hundreds of commands to manage your JBoss A- MQ server. The console also supports limited scripting (think simple BASH shell scripts), and command output pipelining (log:display |grep started
) – try that in your father's server...
Explore the Shell on your own for a little bit. Hit --help
.
Try to give the console following command:
JBoss A-MQ includes a messaging test client as part of its distribution that helps you validate that everything is working correctly. You can download the client jar library () then put it in the <JBoss A-MQ Home>/extras
directory.
To run it we will need another Terminal window. Executing java -jar mq-client.jar
will have it list its options.
In messaging systems there are two (2) types of clients: • Producers – who sending messages • Consumers – who receive messages
So let's continue...
Run the two (2) following command in your Terminal. The only difference between the two (2) is the first argument: producer or consumer. If you try to run this in a single Terminal, you need to run the producer version first, as the consumer will wait (block) for messages. You will ultimately want to have, at least, two Terminal windows going, so you might as well do that now...
java -jar mq-client.jar producer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination queue://summit.test --count 10
Run Consumer:
java -jar mq-client.jar consumer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination queue://summit.test --count 10
The quick version of what the parameters are is:
brokerUrl
– broker connection stringdestination
– JMS destination name – (queue|topic)://count
– number of messages to send (producer) or wait for (consumer)The connection string uses the Apache ActiveMQ failover transport (failover://
prefix) that has the client automatically re-connect when the connection is lost. It is followed by tcp://<hostname>:<port>
.
JBoss A-MQ is a fully compliant JMS 1.1 broker, which means it supports things like JMS Queues. Queues are for point-to-point messaging, that is one and only one consumer will receive any given message. We saw an example of queues in the last lab where we tested a producer and a consumer client against JBoss A-MQ. So now lets see what happens if we have two (2) consumers running...
For this lab, best to have at least four (4) Terminal windows open; Note order of execution is import, so please do the steps below in order
Terminal 2 (Consumer1)
java -jar mq-client.jar consumer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination queue://summit.test --count 50
Terminal 3 (Consumer2)
java -jar mq-client.jar consumer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination queue://summit.test --count 50
Terminal 4 (Producer)
java -jar mq-client.jar producer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination queue://summit.test --count 100 --sleep 100
You should see results like the following
[IMAGE]
Notice how in the Consumers, the messages are interleaving, in this case Consumer1 is getting all the odd numbered messages, and Consumer2 is getting all the even numbered message. In messaging this is called Competing Consumers. JBoss A-MQ will, by default, round robin load balance message dispatch across all the consumers on a Queue.
Try some different combinations for producers and consumers on your own. The most important part is ensuring they are all connecting to the same --destination
(the JMS specification calls Queues and Topics generically Destinations). You can also increase the delay between message send (--sleep
) in the producer if you'd like to try starting a mid-way...
Also try running the producer only, and then the consumer only. You should see A-MQ store the messages in-between. This is a key benefit of JMS Queues in that they allow producers and consumers to communication asynchronously, meaning they don't both have to be running at the same time to receive messages. This can be a big benefit to many systems designs where one system can be done for maintenance, while other systems can continue sending and receiving messages...
JBoss A-MQ is a fully compliant JMS 1.1 broker, which means it also supports things like JMS Topics. Topics are for publishing messages to all subscribers on a names topic. This is different from Queues, as Queues are 1-to-1 and Topics are 1-to-Many, that is all subscribers to a Topic get a copy of the message.
For this lab, best to have at least four (4) Terminal windows open; Note order of execution is import so please do the steps below in order
Terminal 2 (Consumer)
java -jar mq-client.jar consumer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination topic://summit.test --count 10
Terminal 3 (Consumer)
java -jar mq-client.jar consumer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination topic://summit.test --count 10
Terminal 4 (Producer)
java -jar mq-client.jar producer --brokerUrl failover://tcp://localhost:61616 --user admin --password admin --destination topic://summit.test --count 10
You should see results like the following
[IMAGE]
Now this isn't a cut and paste duplicate, you'll see that both consumers received all of the messages sent by the producer.
With a Topic all connected consumers (subscribers) will receive all messages sent by the producers (publishers). The key part is “connected” consumers. A normal Topic consumer only receives messages sent after that consumer connects. This is another big difference from Queues, which will save messages.
Now experiment and try some different combinations. Remember you can add a delay between message sends (--sleep <ms>
), and change the number of messages sent or waited for (--count
).
JBoss A-MQ embeds Apache ActiveMQ, which is providing the bulk of the reliable messaging capabilities. ActiveMQ's configuration is primarily driven by a configuration file located by default in <JBoss A-MQ Home>/etc/activemq.xml
. This configuration file, combined with some property value substitution at load time, determine how the ActiveMQ server will behave.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq- core.xsd">
<!-- Allows us to use system properties and fabric as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<bean class="org.fusesource.mq.fabric.ConfigurationProperties" />
</property>
</bean>
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="${broker-name}" dataDirectory="${data}" start="false">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true">
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="1000" />
</pendingMessageLimitStrategy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb" />
</policyEntries>
</policyMap>
</destinationPolicy>
<managementContext>
<managementContext createConnector="false" />
</managementContext>
<persistenceAdapter>
<kahaDB directory="${data}/kahadb" />
</persistenceAdapter>
<plugins>
<jaasAuthenticationPlugin configuration="karaf" />
</plugins>
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="64 mb" />
</memoryUsage>
<storeUsage>
<storeUsage limit="100 gb" />
</storeUsage>
<tempUsage>
<tempUsage limit="50 gb" />
</tempUsage>
</systemUsage>
</systemUsage>
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:0?maximumConnections=1000" />
</transportConnectors>
</broker>
</beans>
Here's a quick overview of the major components of the ActiveMQ configuration file. You can read more about its configuration here – https://access.redhat.com/site/documentation/JBoss_A-MQ/.
First thing you may notice is that its a Spring file; ActiveMQ is configured using dependency injection.
JBoss A-MQ includes a technology called Fabric that can help with setting up and managing many instances of JBoss A-MQ (and JBoss Fuse). It provides a centralized configuration management and provisioning capability, and it includes a runtime registry that allows clients to auto-discovery where named groups of instances are (host, port, etc.).
In this lab, we're going to configure the first component of a Fabric deployment, the Fabric controller including the Fabric Management Console.
In the Terminal window that has JBoss A-MQ running (if you need to re-start, look at Lab 02 – Starting the JBoss A-MQ server), type the following command
fabric:create --clean --zookeeper-password admin --profile fmc
You will see the Console restart (it will re-display the JBoss A-MQ ASCII art). At this point, this instance of JBoss A-MQ has performed a quick change act under the covers.
fabric:status
and look for the fabric-ensemble-xxx
entry).<tab>
and it will now ask if you want to see all 354 possibilities. Type fabric:<tab>
and you will see many more options than before.That's a lot for one little command...
Before I spend a little time explaining what just happened, this would be a good time to stand and say “I am now the master of my own Fabric!”. You're entering a brave new world, don't look back...
The fabric:create
command had a few components
--clean
– resets your container back to its install state so that if you've installed or uninstalled anything, we'll wipe that away so you're starting in a known state with your new management Fabric.--zookeeper-password <password>
– this is the password token used to allow other container instances to join your Fabric. So if you're friend on the next lab machine wanted to join your Fabric (you know he's always looked up to you), then they could type fabric:join – zookeeper-password <password> <your host>:2181
. The last bit is called the “zookeeperURL”.--profile fmc
– Fabric uses a concept called Profiles, which are a combination of a set of code bits to deploy, and configuration property values for those code bits. Its very easy to create, and version, Profiles in Fabric. This makes it much easier to manage many node deployments. In this case, we told this container to switch to the fmc
profile when it became the Fabric Controller.Enough with the explanations, for now. Let's go to the next lab, and explore the FMC web GUI...
Now that you are master of your own Fabric (if you aren't, follow the steps in Lab 08 – Configuring Fabric), we should also have at our disposal a web GUI. Open your local web browser and go to http://localhost:8181 and you should see something like this...
The login information is what you configured in Lab 01 – Installing JBoss A-MQ (hint: admin/admin). Go ahead and Log In...
Once you’ve logged in, you will be greeted with a welcome screen. Click “Containers” to view your list of containers.
There's a lot here, so let me give you the quick summary of the top tab bar so you can explore on your own.
So go explore on your own for a bit, and then in the next lab we'll walk you though a couple of multiple container configurations. If you manage to really break your environment (perhaps having too much fun clicking buttons, eh?), then you can go back to Lab 07 – Configuring Fabric and clean up before the next lab.
LAB 01 – INSTALLING JBOSS A-MQ
If you are starting from scratch, and not on a lab machine, you can continue this lab section with following instructions.
Installing JBoss A-MQ 6.2 is easy. You'll need to unzip the distribution into the target directory. You can get a JBoss A-MQ distribution from http://www.jboss.org/products/amq.
If you have Subscription, then you can download from Red Hat Customer Portal: https://access.redhat.com/jbossnetwork/restricted/listSoftware.html?product=jboss.amq&downloadType=distributions&version=6.2.0
This will create a subdirectory named
jboss-a-mq-6.2.0.redhat-133
.You will need to edit a couple of configuration files after your first install to setup an administrative username and password.
Edit
<JBoss A-MQ Home>/etc/users.properties
, and uncomment (remove the leading#
) the last line. The format is<username>=<password>,<role>,<role>
. For the purposes of this lab, let's useadmin
as a username and password isadmin
.Go to
<JBoss A-MQ Home>/bin
directory and Start the A-MQ broker using following commandYou will get following output and it will prompt you with A-MQ console
That's it! An install so fast, you don't even have time to get a cup of coffee...