Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 4. Getting Started
This chapter introduces you to AMQ Broker by showing you how to perform the following basic but important tasks:
- Create a broker instance.
- Start a broker instance.
- Stop a broker instance.
- Run the examples included with the installation of AMQ Broker.
4.1. Creating a Broker Instance Copier lienLien copié sur presse-papiers!
A broker instance is a directory containing all the configuration and runtime data, such as logs and data files. The runtime data is associated with a unique broker process.
Creating a Broker Instance on Linux
Procedure
Create a directory location for the broker instance, for example
/var/opt/amq-broker
, and assign the user you created during installation as its owner:sudo mkdir /var/opt/amq-broker sudo chown -R amq-broker:amq-broker /var/opt/amq-broker
$ sudo mkdir /var/opt/amq-broker $ sudo chown -R amq-broker:amq-broker /var/opt/amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Move to the new directory and use the
artemis create
command to create a broker. For example, to create the broker instancemybroker
under the/var/opt/amq-broker
directory, run the following commands. Note that in the following example the user that was created during installation is the one to run thecreate
command:su - amq-broker cd /var/opt/amq-broker INSTALL_DIR/bin/artemis create mybroker
$ su - amq-broker $ cd /var/opt/amq-broker $ INSTALL_DIR/bin/artemis create mybroker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Creating a Broker Instance on Windows
Procedure
- Using Windows Explorer create a new folder to serve as the location for the broker instance.
Open a Windows command prompt from the location you just created and use the
artemis.cmd create
command to create a broker. For example, to create the broker instancemybroker
, run the following command:> INSTALL_DIR\bin\artemis.cmd create mybroker
> INSTALL_DIR\bin\artemis.cmd create mybroker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Responding to Questions Asked During the Creation Process
The create command will ask a series of questions to configure the broker instance. It will prompt for mandatory property value only. For the full list of properties available when creating an instance, run the artemis help create
command.
The following example shows the command-line interactive process when creating a broker instance.
Broker Instance Directory Contents
The process creates a top level directory and several subdirectories containing configuration and runtime data. In the preceding examples, the top level directory is named mybroker
. The documentation refers to the top level location as the BROKER_INSTANCE_DIR
. The table below details its structure and contents.
If you want to find… | Look here… |
---|---|
Scripts that launch and manage the instance |
|
Configuration files |
|
Storage for persistent messages |
|
Log files |
|
Temporary files |
|
4.2. Starting a Broker Instance Copier lienLien copié sur presse-papiers!
After the broker is created, use the artemis
script in the BROKER_INSTANCE_DIR/bin
directory to start it. For instance, to start a broker created at /var/opt/amq-broker/mybroker
, use the following command as the user you created during installation. In the following example, the user amq-broker
starts the broker:
su - amq-broker /var/opt/amq-broker/mybroker/bin/artemis run
$ su - amq-broker
$ /var/opt/amq-broker/mybroker/bin/artemis run
The artemis
command has other other options available. Provide the help
parameter to learn more:
/var/opt/amq-broker/mybroker/bin/artemis help
$ /var/opt/amq-broker/mybroker/bin/artemis help
When started, the broker will produce output similar to the following:
4.2.1. Starting a Broker as a Linux Service Copier lienLien copié sur presse-papiers!
If the broker is installed on Linux, you can run it as a service.
Procedure
-
Create a new
amq-broker.service
file in the/etc/systemd/system/
directory. Copy the following text into the file.
Modify the path and user fields according to the information provided during the broker instance creation. In the example below, the user
amq-broker
starts the broker service installed under the/var/opt/amq-broker/mybroker/
directory.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Open a terminal.
Enable the broker service using the following command:
sudo systemctl enable amq-broker
sudo systemctl enable amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the broker service using the following command:
sudo systemctl start amq-broker
sudo systemctl start amq-broker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2.2. Starting a Broker as a Windows Service Copier lienLien copié sur presse-papiers!
If the broker is installed on Windows, you can run it as a service.
Procedure
The following steps require that you open a command prompt to enter the commands.
Install the broker as a service with the following command:
BROKER_INSTANCE_DIR\bin\artemis-service.exe install
BROKER_INSTANCE_DIR\bin\artemis-service.exe install
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the service by using the following command:
BROKER_INSTANCE_DIR\bin\artemis-service.exe start
BROKER_INSTANCE_DIR\bin\artemis-service.exe start
Copy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) Uninstall the service:
BROKER_INSTANCE_DIR\bin\artemis-service.exe uninstall
BROKER_INSTANCE_DIR\bin\artemis-service.exe uninstall
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3. Stopping a Broker Instance Copier lienLien copié sur presse-papiers!
You can stop the broker manually by issuing the stop
command. Immediately after the command is entered, all connections to the broker are forcefully stopped and the shutdown process begins.
Procedure
Stop the broker.
If you are running the broker on Linux, issue the following command:
BROKER_INSTANCE_DIR\bin\artemis stop
BROKER_INSTANCE_DIR\bin\artemis stop
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are running the broker on Windows as a service, issue the following command:
BROKER_INSTANCE_DIR\bin\artemis-service.exe stop
BROKER_INSTANCE_DIR\bin\artemis-service.exe stop
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3.1. Stopping a Broker Instance Gracefully Copier lienLien copié sur presse-papiers!
A manual shutdown forcefully disconnects all clients after a stop command is entered. As an alternative, configure the broker to shutdown gracefully by using the graceful-shutdown-enabled
configuration element.
When graceful-shutdown-enabled
is set to true
, no new client connections are allowed after a stop command is entered. However, existing connections are allowed to close on the client-side before the shutdown process is started. The default value for graceful-shutdown-enabled
is false
.
Use the graceful-shutdown-timeout
configuration element to set a length of time, in milliseconds, for clients to disconnect before connections are forcefully closed from the broker side. After all connections are closed, the shutdown process is started. One advantage of using graceful-shutdown-timeout
is that it prevents client connections from delaying a shutdown. The default value for graceful-shutdown-timeout
is -1
, meaning the broker waits indefinitely for clients to disconnect.
The following procedure demonstrates how to configure a graceful shutdown that uses a timeout.
Procedure
-
Open the configuration file
BROKER_INSTANCE_DIR\etc\broker.xml
. Add the
graceful-shutdown-enabled
configuration element and set the value totrue
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the
graceful-shutdown-timeout
configuration element and set a value for the timeout in milliseconds. In the following example, client connections are forcefully closed 30 seconds (30000
milliseconds) after the stop command is issued.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.4. Running the Included Examples Copier lienLien copié sur presse-papiers!
AMQ Broker ships with many example programs that highlight various basic and advanced features of the product. They can be found under INSTALL_DIR/examples
.
The examples require a supported release of the Java Development Kit (JDK) and Maven version 3.2 or greater to build and run. Consult Supported Configurations for details about JDK support. The next section shows you how to install and configure Maven, enabling you to run the examples.
Downloading Maven and the AMQ Repository
Running the examples requires that both Maven and the Red Hat AMQ Broker Maven repository are installed locally. The steps below show you how to download, install, and configure both. For more information about Maven refer to the appendix.
Downloading and Installing Maven
- Go to Apache Maven Project - Download Maven and download the latest distribution for your operating system.
Install Maven for your operating system.
For more information, see Installing Apache Maven.
Downloading and Installing the AMQ Maven Repository
- Open a browser and log in to the Red Hat Customer Portal at https://access.redhat.com.
- Click Downloads.
- Find Red Hat AMQ in the Product Downloads list.
- Select Download Latest Broker from the drop-down list located on the same row to go to the Software Downloads page for AMQ Broker.
- From the Software Downloads page, select the correct AMQ Broker version from the Version drop-down menu.
- Click the Download link for the Maven Repository to download a .zip file containing the repository.
Unzip the file on the local file system into a directory of your choosing.
This creates a new directory, which contains the Maven repository in a subdirectory named
maven-repository/
.
If you want to continue to use an older local repository, you must configure it separately in the Maven settings.xml
configuration file. Each local repository must be configured within its own <repository>
element.
Remove the cached repository/
subdirectory located under the .m2/
directory before attempting to use a new Maven repository.
Configuring the Maven Settings File
Locate the Maven
settings.xml
file for your operating system. It is usually located in the${user.home}/.m2/
directory.-
For Linux or Mac, this is
~/.m2/
-
For Windows, this is
\Documents and Settings\.m2\
or\Users\.m2\
-
For Linux or Mac, this is
-
(Optional) If you do not find a
settings.xml
file in${user.home}/.m2/
, there is a default version located in theconf/
directory of your Maven installation. Copy the defaultsettings.xml
file into the${user.home}/.m2/
directory. Copy the following XML into the
<profiles>
element of thesettings.xml
file.Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Replace JBOSS_AMQ_REPOSITORY_PATH within the
url
element with the location of the maven repository on the local file system. If you followed the installation steps above, the location should end with/maven-repository
. Copy the following XML into the
<activeProfiles>
element of thesettings.xml
file.<activeProfile>jboss-amq-maven-repository</activeProfile>
<activeProfile>jboss-amq-maven-repository</activeProfile>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
(Optional) If you copied the default
settings.xml
from your Maven installation, uncomment the<active-profiles>
section if it was commented out by default.
If your Maven repository contains outdated artifacts, you may encounter one of the following Maven error messages when you build or deploy your project:
- Missing artifact ARTIFACT_NAME
- [ERROR] Failed to execute goal on project PROJECT_NAME; Could not resolve dependencies for PROJECT_NAME
To resolve the issue, delete the cached version of your local repository to force a download of the latest Maven artifacts. The cached repository is located here: ${user.home}/.m2/repository/
Several of the examples use UDP clustering, which may not work in your environment when you first attempt to run them. On Linux, you can issue a command to provide the appropriate environment. The following command redirects any traffic directed to 224.0.0.0 to the loopback interface, allowing examples that use UDP clustering to run successfully:
sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev lo
sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev lo
Running the queue
Example to Test Your Installation
To run any example, change directories to the desired example and type mvn clean verify
. You can also use the profile -P examples
to run multiple examples under any example directory tree. For details on each example, read the readme.html
file in each example directory. An excellent example to use as a "sanity test" of your broker installation is the queue
example. The example creates a producer to send a message to the broker and a consumer that receives the same message.
Procedure
To build and run the example, navigate to the
INSTALL_DIR/examples/features/standard/queue
directory:cd INSTALL_DIR/examples/features/standard/queue
$ cd INSTALL_DIR/examples/features/standard/queue
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
mvn clean verify
command:mvn clean verify
$ mvn clean verify
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Maven will start the broker and run the example. When completed the output should look something like the following example. Note that the example may take a long time to run the first time since Maven will download any missing dependencies required to run the example.