このコンテンツは選択した言語では利用できません。
Chapter 4. Creating a standalone broker
You can get started quickly with AMQ Broker by creating a standalone broker instance on your local machine, starting it, and producing and consuming some test messages.
Prerequisites
AMQ Broker must be installed.
For more information, see Chapter 3, Installing AMQ Broker.
4.1. Creating a broker instance リンクのコピーリンクがクリップボードにコピーされました!
A broker instance is a directory containing the configuration and runtime data for a broker. To create a new broker instance, you first create a directory for the broker instance, and then use the artemis create
command to create the broker instance.
This procedure demonstrates how to create a simple, standalone broker on your local machine. The broker uses a basic, default configuration, and accepts connections from clients using any of the supported messaging protocols.
Procedure
Create a directory for the broker instance.
Expand If you are using… Do this… Red Hat Enterprise Linux
Create a new directory to serve as the location for the broker instance.
sudo mkdir /var/opt/amq-broker
$ sudo mkdir /var/opt/amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the user that you created during installation.
sudo chown -R amq-broker:amq-broker /var/opt/amq-broker
$ sudo chown -R amq-broker:amq-broker /var/opt/amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Windows
Use Windows Explorer to create a new folder to serve as the location for the broker instance.
Use the
artemis create
command to create the broker.Expand If you are using… Do this… Red Hat Enterprise Linux
Switch to the user account you created during installation.
su - amq-broker
$ su - amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change to the directory you just created for the broker instance.
cd /var/opt/amq-broker
$ cd /var/opt/amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow From the broker instance’s directory, create the broker instance.
<install-dir>/bin/artemis create mybroker
$ <install-dir>/bin/artemis create mybroker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Windows
- Open a command prompt from the directory you just created for the broker instance.
From the broker instance’s directory, create the broker instance.
> <install-dir>\bin\artemis.cmd create mybroker
> <install-dir>\bin\artemis.cmd create mybroker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Follow the
artemis create
prompts to configure the broker instance.Example 4.1. Configuring a broker instance using
artemis create
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2. Starting the broker instance リンクのコピーリンクがクリップボードにコピーされました!
After the broker instance is created, you use the artemis run
command to start it.
Procedure
Switch to the user account you created during installation.
su - amq-broker
$ su - amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
artemis run
command to start the broker instance.Copy to Clipboard Copied! Toggle word wrap Toggle overflow The broker starts and displays log output with the following information:
- The location of the transaction logs and cluster configuration.
- The type of journal being used for message persistence (AIO in this case).
The URI(s) that can accept client connections.
By default, port 61616 can accept connections from any of the supported protocols (CORE, MQTT, AMQP, STOMP, HORNETQ, and OPENWIRE). There are separate, individual ports for each protocol as well.
- The web console is available at http://localhost:8161.
- The Jolokia service (JMX over REST) is available at http://localhost:8161/jolokia.
4.3. Producing and consuming test messages リンクのコピーリンクがクリップボードにコピーされました!
After starting the broker, you should verify that it is running properly. This involves producing a few test messages, sending them to the broker, and then consuming them.
Procedure
Use the
artemis producer
command to produce a few test messages and send them to the broker.This command sends 100 messages to the
helloworld
address, which is created automatically on the broker. The producer connects to the broker by using the default port 61616, which accepts all supported messaging protocols.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the web console to see the messages stored in the broker.
- In a web browser, navigate to http://localhost:8161.
Log into the console using the default username and default password that you created when you created the broker instance.
The
Attributes
tab is displayed.On the
Attributes
tab, navigate to menu:[addresses > helloworld > queues > "anycast" > helloworld].In the previous step, you sent messages to the
helloworld
address. This created a new anycasthelloworld
address with a queue (also namedhelloworld
). TheMessage count
attribute shows that all 100 messages that were sent tohelloworld
are currently stored in this queue.Figure 4.1. Message count
Use the
artemis consumer
command to consume 50 of the messages stored on the broker.This command consumes 50 of the messages that you sent to the broker previously.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the web console, verify that the
Message count
is now 50.50 of the messages were consumed, which leaves 50 messages stored in the
helloworld
queue.Stop the broker and verify that the 50 remaining messages are still stored in the
helloworld
queue.- In the terminal in which the broker is running, press Ctrl+C to stop the broker.
Restart the broker.
/var/opt/amq-broker/mybroker/bin/artemis run
$ /var/opt/amq-broker/mybroker/bin/artemis run
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
In the web console, navigate back to the
helloworld
queue and verify that there are still 50 messages stored in the queue.
Consume the remaining 50 messages.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the web console, verify that the
Message count
is 0.All of the messages stored in the
helloworld
queue were consumed, and the queue is now empty.
4.4. Stopping the broker instance リンクのコピーリンクがクリップボードにコピーされました!
After creating the standalone broker and producing and consuming test messages, you can stop the broker instance.
This procedure manually stops the broker, which forcefully closes all client connections. In a production environment, you should configure the broker to stop gracefully so that client connections can be closed properly.
Procedure
Use the
artemis stop
command to stop the broker instance:/var/opt/amq-broker/mybroker/bin/artemis stop
$ /var/opt/amq-broker/mybroker/bin/artemis stop 2018-12-03 14:37:30,630 INFO [org.apache.activemq.artemis.core.server] AMQ221002: Apache ActiveMQ Artemis Message Broker version 2.6.1.amq-720004-redhat-1 [b6c244ef-f1cb-11e8-a2d7-0800271b03bd] stopped, uptime 35 minutes Server stopped!
Copy to Clipboard Copied! Toggle word wrap Toggle overflow