Command-line tool (Windows/macOS/Linux) to interact with a JMX enabled Apache ActiveMQ message broker.
Your broker is not JMX enabled? Check out amazonmq-cli.
Here is a three minute video that shows how to install, configure and use ActiveMQ CLI.
Download activemq-cli in the release section of this repository.
Unzip the activemq-cli-x.x.x.zip file and configure the broker you want to connect to in activemq-cli-x.x.x/conf/activemq-cli.config
:
broker {
local {
amqurl = "tcp://localhost:61616"
jmxurl = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"
username = ""
password = ""
prompt-color = "light-blue"
}
// add additional brokers here
dev {
amqurl = "tcp://development-server:61616"
jmxurl = "service:jmx:rmi:///jndi/rmi://development-server:1099/jmxrmi"
username = "admin"
password = "admin"
}
prod {
amqurl = "tcp://production-server:61616"
jmxurl = "service:jmx:rmi:///jndi/rmi://production-server:1099/jmxrmi"
}
fuse-server {
amqurl = "tcp://fuse-server:61616"
jmxurl = "service:jmx:rmi:///jndi/rmi://fuse-server:1099/karaf-root"
}
ssl-server {
amqurl = "ssl://ssl-server:61616"
jmxurl = "service:jmx:rmi:///jndi/rmi://ssl-server:1099/jmxrmi"
// SSL
keyStore = "~/client.ks"
keyStorePassword = "secret"
trustStore = "~/client.ts"
}
}
To enter the activemq-cli shell run activemq-cli-x.x.x/bin/activemq-cli
or activemq-cli-x.x.x/bin/activemq-cli.bat
if you are using Windows.
activemq-cli provides tab completion to speed up typing commands, to see which commands are available and what parameters are supported.
In addition to executing commands in the shell, activemq-cli also supports executing a file containing commands:
activemq-cli --cmdfile my_commands.txt
To connect to a broker that is configured in activemq-cli-x.x.x/conf/activemq-cli.config
: connect --broker dev
Below is a list of commands that activemq-cli supports.
Adds a queue.
- name
Example:add-queue --name foo
Adds a topic.
- name
Example:add-topic --name foo
Connects activemq-cli to a broker.
- broker (broker must be defined in
activemq-cli-x.x.x/conf/activemq-cli.config
)
Example:connect --broker local
Copies messages from a queue to another queue.
- from
- to
- selector (copy messages that match the (JMS) selector)
Example:copy-messages --from foo --to bar
Disconnects activemq-cli from the broker.
Example:disconnect
Exports queues, topics and messages to file.
- file
Example:export-broker --file broker.xml
For this command activemq-cli creates temporary mirror queues to ensure all messages are exported.
Exports messages to file.
- file
- queue
- selector (export messages that match the (JMS) selector)
- regex (export messages whose body match the regex)
Example:export-messages --queue foo
For this command activemq-cli creates a temporary mirror queue to ensure all messages are exported.
Displays information (e.g. version, uptime, total number of queues/topics/messages) about the broker
Example:info
Lists messages.
- queue
- selector (lists messages that match the (JMS) selector)
- regex (lists messages whose body match the regex)
Example 1:list-messages --queue foo
Example 2:list-messages --queue foo --selector "JMSCorrelationID = '12345'"
Example 3:list-messages --queue foo --regex bar
For this command activemq-cli creates a temporary mirror queue to ensure all messages are listed.
Lists queues.
- filter (list queues with the specified filter in the name)
- exclude-filter (list queues without the specified exclude-filter in the name)
- pending (list queues for which the number of pending messages meets the pending filter)
- enqueued (list queues for which the number of enqueued messages meets the enqueued filter)
- dequeued (list queues for which the number of dequeued messages meets the dequeued filter)
- consumers (list queues for which the number of consumers meets the consumers filter)
Example 1:queues --filter foo
Example 2:queues --pending >0 --consumers =0
Lists topics.
- filter (list topics with the specified filter in the name)
- enqueued (remove topics for which the number of enqueued messages meets the enqueued filter)
- dequeued (remove topics for which the number of dequeued messages meets the dequeued filter)
Example 1:topics --filter foo
Example 2:topics --enqueued >0
Moves messages from a queue to another queue.
- from
- to
- selector (move messages that match the (JMS) selector)
Pauses a queues.
- name
- force (no prompt for confirmation)
Example:pause-queue --name foo
Purges all queues.
- force (no prompt for confirmation)
- dry-run (use this to test what is going to be purged, no queues are actually purged)
- filter (queues with the specified filter in the name)
- exclude-filter (list queues without the specified exclude-filter in the name)
- pending (purge queues for which the number of pending messages meets the pending filter)
- enqueued (purge queues for which the number of enqueued messages meets the enqueued filter)
- dequeued (purge queues for which the number of dequeued messages meets the dequeued filter)
- consumers (purge queues for which the number of consumers meets the consumers filter)
Example 1:purge-all-queues
Example 2:purge-all-queues --filter foo --consumers =0 --dry-run
Purges a queues.
- name
- force (no prompt for confirmation)
Example:purge-queue --name foo
Displays the release notes.
Example:release-notes
Removes all queues.
- force (no prompt for confirmation)
- dry-run (use this to test what is going to be removed, no queues are actually removed)
- filter (queues with the specified filter in the name)
- exclude-filter (list queues without the specified exclude-filter in the name)
- pending (remove queues for which the number of pending messages meets the pending filter)
- enqueued (remove queues for which the number of enqueued messages meets the enqueued filter)
- dequeued (remove queues for which the number of dequeued messages meets the dequeued filter)
- consumers (remove queues for which the number of consumers meets the consumers filter)
Example 1:remove-all-queues
Example 2:remove-all-queues --filter foo --consumers =0 --dry-run
Removes all topics.
- force (no prompt for confirmation)
- dry-run (use this to test what is going to be removed, no queues are actually removed)
- filter (queues with the specified filter in the name)
- enqueued (remove topics for which the number of enqueued messages meets the enqueued filter)
- dequeued (remove topics for which the number of dequeued messages meets the dequeued filter)
Example 1:remove-all-topics
Example 2:remove-all-topics --filter foo --enqueued =0 --dry-run
Removes a queue.
- name
- force (no prompt for confirmation)
Example:remove-queue --name foo
Removes a topic.
- name
- force (no prompt for confirmation)
Example:remove-topic --name foo
Resumes a queues.
- name
- force (no prompt for confirmation)
Example:resume-queue --name foo
Sends a message or file of messages to a queue or topic.
- body
- queue
- topic
- priority (not applicable if -file is specified)
- correlation-id (not applicable if -file is specified)
- reply-to (not applicable if -file is specified)
- delivery-mode (not applicable if -file is specified)
- time-to-live (not applicable if -file is specified)
- times (number of times the message is sent)
- type (not applicable if -file is specified)
- file
Example file:
<jms-messages>
<jms-message>
<body>Message 1</body>
</jms-message>
<jms-message>
<body>Message 2</body>
</jms-message>
<jms-message>
<header>
<priority>0</priority>
<correlation-id>12345</correlation-id>
<reply-to>myRepliesQueue</reply-to>
<delivery-mode>2</delivery-mode>
<time-to-live>1000</time-to-live>
<type>myCustomType</type>
</header>
<properties>
<property>
<name>my_custom_property</name>
<value>1</value>
</property>
</properties>
<body><![CDATA[<?xml version="1.0"?>
<catalog>
<book id="1">
<author>Basil, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2002-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>
</catalog>]]></body>
</jms-message>
</jms-messages>
Example 1:send-message --body foo --queue bar
Example 2:send-message --file foo.xml --topic bar
Starts the embedded broker.
The embedded broker is configured in activemq-cli-x.x.x/conf/activemq-cli.config
:
embedded-broker {
connector = "tcp://localhost:61616"
jmxport = 1099
}
Example:start-embedded-broker
Stops the embedded broker.
Example:stop-embedded-broker