ActiveMQ Artemis CheatSheet

This is my Artemis MQ Artemis Cheatsheet which includes some commandline shortcuts you can use to manage your broker as well as producing and consuming messages and checking their status.

Introduction

Firstly, if you are new to Artemis MQ, we recommend checking this article for an introduction to the Messaging Broker and details on how to install an instance of the broker on your machine: Getting started with ActiveMQ Artemis

Besides, to complement this article we also recommend checking this excellent resource from Roman Martin: My own ActiveMQ Artemis Cheat Sheet – Roman’s Blog (jromanmartin.io)

Base Artemis Commands

Creating a Broker Instance:

./artemis create myartemis --user admin --password admin --queues queueDemo --require-login

This command creates a new Artemis broker instance “myartemis”.It sets the username and password for admin access to “admin”.It creates a queue “queueDemo” within the broker. The --require-login flag enforces authentication for accessing the broker.

Checking Queue Status:

./artemis queue stat --user admin --password admin --url=tcp://localhost:61616 --maxRows 100
  • This command retrieves statistics about queues in the broker.
  • It connects to the broker running on localhost port 61616.
  • It uses credentials “admin” and “admin” to authenticate.
  • --maxRows 100 specifies displaying a maximum of 100 rows of data (optional).
./artemis queue stat --user admin --password admin --queueName "SampleQueue" --url=tcp://localhost:61616

This command retrieves specific statistics for the queue named “SampleQueue”.

Verifying Queue Existence:

./artemis check queue --user admin --password admin --name "SampleQueue" --url=tcp://localhost:61616
  • This command checks if a specific queue exists and it is not paused.

Getting Artemis Version:

./artemis version
  • This command displays the installed version of Apache ActiveMQ Artemis.

Browsing, Sending and Consuming Messages

Browsing Messages:

./artemis browser --destination "SampleQueue" --user admin --password admin --url tcp://localhost:61616 --message-count 10
  • This command allows you to browse messages in a queue.
  • It specifies the “SampleQueue” as the destination.
  • It uses credentials for authentication.
  • --message-count 10 retrieves and displays up to 10 messages (optional).

Consuming Messages:

./artemis consumer --url tcp://localhost:61616 --user admin --password admin --destination "SampleQueue" --verbose
  • This command defines a message consumer that listens for and processes messages from “SampleQueue”.
  • The --verbose flag provides more details about received messages (optional).

Producing Messages:

./artemis producer --url tcp://localhost:61616 --user admin --password admin --destination "SampleQueue" --message "Sample Message" --message-count 1
  • This command creates a message producer that sends a single message with the text “Sample Message” to “SampleQueue”.

Sending Messages to a Specific Group:

./artemis producer --url tcp://localhost:61616 --user admin --password admin --destination "SampleQueue" --message-count 1 --group mygroup
  • Finally, this command sends a message similar to the previous one, but assigns it a group identifier “mygroup”. This might be used for message routing within the broker.

User Management

  • These commands allow you to create, reset, and delete users with specific roles within the broker. They all require admin credentials and specify the broker URL.
# add user user1 with password user1-password1 and role role1
./artemis user add --url tcp://localhost:61616 --user admin --password admin --user-command-user user1 --user-command-password user1-password1 --role role1

# reset user1 changing the password
./artemis user reset --url tcp://localhost:61616 --user admin --password admin --user-command-user user1 --user-command-password user1-password2 --role role1

#delete user1
./artemis user rm --url tcp://localhost:61616 --user admin --password admin  --user-command-user user1

Operations / Attributes

Reading Attributes and running Operations on a Queue

Artemis MQ Web Console is an excellent tool to read Queue attributes and perform operations on your them. On the other hand, you can automate some of these tasks using the Jolokia API which you can use with any HTTP tool like curl.

For example, supposing you want to read the MessageCount attribute for a Queue:

artemis mq cheatsheet

You can achieve the same result with the following command:

curl -v -u admin:admin -H Origin:http://artemis-hostname artemis-hostname:8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"broker_name\",component=addresses,address=\"MyQueueAddress\",subcomponent=queues,routing-type=\"anycast\",queue=\"SampleQueue\"/MessageCount
  • This command utilizes the curl tool to access the broker’s JMX interface (management) and retrieve the message count for “SampleQueue”. Replace artemis-hostname with the actual Artemis MQ Hostname. Also, replace admin:admin with the current Administration Password. Finally, set the Address and Queue name replacing MyQueueAddress and SampleQueue

Conclusion

This Artemis MQ cheatsheet provides a foundational overview of essential command-line tools for managing your message broker. From creating and configuring your broker to producing, consuming, and browsing messages, you now have a solid grasp of the basics.