此内容没有您所选择的语言版本。
Chapter 24. Management
AMQ Broker provides both a graphical as well as a programming interface to help you manage your brokers.
24.1. Using AMQ Console 复制链接链接已复制到粘贴板!
If you prefer to use a graphic interface to manage AMQ, you can use AMQ Console. AMQ Console is a web console included in the AMQ Broker installation, and it enables you to use a web browser to manage AMQ Broker and AMQ Interconnect.
For more information, see Using AMQ Console.
24.2. Using the Management API 复制链接链接已复制到粘贴板!
AMQ Broker 7.1 has an extensive management API that allows a user to modify a broker’s configuration, create new resources (for example, addresses and queues), inspect these resources (for example, how many messages are currently held in a queue), and interact with them (for example, to remove messages from a queue). Using the management API, clients can also manage the broker and subscribe to management notifications.
There are two ways to manage the broker:
- Using JMX — JMX is the standard way to manage Java applications
- Using the JMS API — management operations are sent to the broker using JMS messages and the AMQ JMS client
Although there are two different ways to manage the broker, each API supports the same functionality. If it is possible to manage a resource using JMX it is also possible to achieve the same result by using JMS messages and the AMQ JMS client.
This choice depends on your particular requirements, application settings, and environment.
Regardless of the way you invoke management operations, the management API is the same.
For each managed resource, there exists a Java interface describing what can be invoked for this type of resource.
The broker exposes its managed resources in the org.apache.activemq.artemis.api.core.management package.
The way to invoke management operations depends on whether JMX messages or JMS messages and the AMQ JMS client is used.
A few management operations require a filter parameter to choose which messages are affected by the operation. Passing null or an empty string means that the management operation will be performed on all messages.
24.2.1. Managing the Broker 复制链接链接已复制到粘贴板!
- Listing, creating, deploying, and destroying queues
A list of deployed queues can be retrieved using the
getQueueNames()method.Queues can be created or destroyed using the management operations
createQueue(),deployQueue(), ordestroyQueue()on theActiveMQServerControl(with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME"or the resource nameserver).createQueuewill fail if the queue already exists whiledeployQueuewill do nothing.- Pausing and resuming queues
-
The
QueueControlcan pause and resume the underlying queue. When a queue is paused, it will receive messages but will not deliver them. When it is resumed, it will begin delivering the queued messages, if any. - Listing and closing remote connections
-
Retrieve a client’s remote addresses by using
listRemoteAddresses(). It is also possible to close the connections associated with a remote address using thecloseConnectionsForAddress()method. -
Alternatively, list connection IDs using
listConnectionIDs()and list all the sessions for a given connection ID usinglistSessions().
-
Retrieve a client’s remote addresses by using
- Managing transactions
In case of a broker crash, when the broker restarts, some transactions might require manual intervention. Use the the following methods to help resolve issues you encounter.
-
List the transactions which are in the prepared states (the transactions are represented as opaque Base64 Strings) using the
listPreparedTransactions()method lists. -
Commit or rollback a given prepared transaction using
commitPreparedTransaction()orrollbackPreparedTransaction()to resolve heuristic transactions. -
List heuristically completed transactions using the
listHeuristicCommittedTransactions()andlistHeuristicRolledBackTransactionsmethods.
-
List the transactions which are in the prepared states (the transactions are represented as opaque Base64 Strings) using the
- Enabling and resetting message counters
-
Enable and disable message counters using the
enableMessageCounters()ordisableMessageCounters()method. -
Reset message counters by using the
resetAllMessageCounters()andresetAllMessageCounterHistories()methods.
-
Enable and disable message counters using the
- Retrieving broker configuration and attributes
-
The
ActiveMQServerControlexposes the broker’s configuration through all its attributes (for example,getVersion()method to retrieve the broker’s version, and so on). - Listing, creating, and destroying Core Bridge and diverts
-
List deployed Core Bridge and diverts using the
getBridgeNames()andgetDivertNames()methods respectively. -
Create or destroy using bridges and diverts using
createBridge()anddestroyBridge()orcreateDivert()anddestroyDivert()on theActiveMQServerControl(with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME"or the resource nameserver).
-
List deployed Core Bridge and diverts using the
- Stopping the broker and forcing failover to occur with any currently attached clients
Use the
forceFailover()on theActiveMQServerControl(with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME"or the resource nameserver)NoteSince this method actually stops the broker you will probably receive some sort of error depending on which management service you use to call it.
24.2.2. Managing Addresses 复制链接链接已复制到粘贴板!
Manage addresses using the AddressControl class (with the ObjectName org.apache.activemq.artemis:broker="BROKER_NAME",component=addresses,address="ADDRESS_NAME" or the resource name address.ADDRESS_NAME).
-
Modify roles and permissions for an address using the
addRole()orremoveRole()methods. You can list all the roles associated with the queue with thegetRoles()method.
24.2.3. Managing Queues 复制链接链接已复制到粘贴板!
The bulk of the core management API deals with queues. The QueueControl class defines the queue management operations (with the ObjectName org.apache.activemq.artemis:broker="BROKER_NAME",component=addresses,address="BOUND_ADDRESS",subcomponent=queues,routing-type="ROUTING_TYPE",queue="QUEUE_NAME" or the resource name queue.QUEUE_NAME).
Most of the management operations on queues take either a single message ID (for example, to remove a single message) or a filter (for example, to expire all messages with a given property.)
- Expiring, sending to a dead letter address, and moving messages
-
Expire messages from a queue using the
expireMessages()method. If an expiry address is defined, messages will be sent to it, otherwise they are discarded. The queue’s expiry address can be set with thesetExpiryAddress()method. -
Send messages to a dead letter address with the
sendMessagesToDeadLetterAddress()method. It returns the number of messages which are sent to the dead letter address. If a dead letter address is not defined, messages are removed from the queue and discarded. The queue’s dead letter address can be set with thesetDeadLetterAddress()method. -
Move messages from one queue to another by using the
moveMessages()method.
-
Expire messages from a queue using the
- Listing and removing messages
-
List messages from a queue using the
listMessages()method. It will return an array ofMap, oneMapfor each message. -
Remove messages from a queue using the
removeMessages()method, which returns abooleanfor the single message ID variant or the number of removed messages for the filter variant. This method takes afilterargument to remove only filtered messages. Setting the filter to an empty string will in effect remove all messages. Counting messages
The number of messages in a queue is returned by the
getMessageCount()method. Alternatively, thecountMessages()will return the number of messages in the queue which match a given filter.Changing message priority
The message priority can be changed by using the
changeMessagesPriority()method which returns abooleanfor the single message ID variant or the number of updated messages for the filter variant.Message counters
Message counters can be listed for a queue with the
listMessageCounter()andlistMessageCounterHistory()methods (see the Message Counters section). The message counters can also be reset for a single queue using theresetMessageCounter()method.Retrieving the queue attributes
The
QueueControlexposes queue settings through its attributes (for example,getFilter()to retrieve the queue’s filter if it was created with one,isDurable()to know whether the queue is durable, and so on).Pausing and resuming queues
The
QueueControlcan pause and resume the underlying queue. When a queue is paused, it will receive messages but will not deliver them. When it is resumed, it will begin delivering the queued messages, if any.
-
List messages from a queue using the
24.2.3.1. Managing Other Resources 复制链接链接已复制到粘贴板!
You can start and stop the broker’s remote resources (acceptors, diverts, bridges, and so on) so that a broker can be taken offline for a given period of time without stopping it completely (for example, if other management operations must be performed, such as resolving heuristic transactions). These resources are:
Acceptors
Start or stop an acceptor using the
start()or.stop()method on theAcceptorControlclass (with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME",component=acceptors,name="ACCEPTOR_NAME"or the resource nameacceptor.ADDRESS_NAME). Acceptor parameters can be retrieved using theAcceptorControlattributes. See Network Connections:Acceptors and Connectors for more information about Acceptors.Diverts
Start or stop a divert using the
start()orstop()method on theDivertControlclass (with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME",component=diverts,name="DIVERT_NAME"or the resource namedivert.DIVERT_NAME). Divert parameters can be retrieved using theDivertControlattributes.Bridges
Start or stop a bridge using the
start()(resp.stop()) method on theBridgeControlclass (with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME",component=bridge,name="BRIDGE_NAME"or the resource namebridge.BRIDGE_NAME). Bridge parameters can be retrieved using theBridgeControlattributes. See Clustering for more information.Broadcast groups
Start or stop a broadcast group using the
start()orstop()method on theBroadcastGroupControlclass (with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME",component=broadcast-group,name="BROADCAST_GROUP_NAME"or the resource namebroadcastgroup.BROADCAST_GROUP_NAME). Broadcast group parameters can be retrieved using theBroadcastGroupControlattributes. See Clustering for more information.Discovery groups
Start or stop a discovery group using the
start()orstop()method on theDiscoveryGroupControlclass (with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME",component=discovery-group,name="DISCOVERY_GROUP_NAME"or the resource namediscovery.DISCOVERY_GROUP_NAME). Discovery groups parameters can be retrieved using theDiscoveryGroupControlattributes. See Clustering for more information.Cluster connections
Start or stop a cluster connection using the
start()orstop()method on theClusterConnectionControlclass (with theObjectNameorg.apache.activemq.artemis:broker="BROKER_NAME",component=cluster-connection,name="CLUSTER_CONNECTION_NAME"or the resource nameclusterconnection.CLUSTER_CONNECTION_NAME). Cluster connection parameters can be retrieved using theClusterConnectionControlattributes. See Clustering for more information.
24.2.4. Managing the Broker Using JMX 复制链接链接已复制到粘贴板!
The broker can be managed using JMX. The management API is exposed by the broker using MBeans interfaces. The broker registers its resources with the domain org.apache.activemq.
For example, the ObjectName to manage a queue named exampleQueue is:
org.apache.activemq.artemis:broker="__BROKER_NAME__",component=addresses,address="exampleQueue",subcomponent=queues,routingtype="anycast",queue="exampleQueue"
org.apache.activemq.artemis:broker="__BROKER_NAME__",component=addresses,address="exampleQueue",subcomponent=queues,routingtype="anycast",queue="exampleQueue"
and the MBean is:
org.apache.activemq.artemis.api.management.QueueControl
org.apache.activemq.artemis.api.management.QueueControl
The MBean’s ObjectName is built using the helper class org.apache.activemq.artemis.api.core.management.ObjectNameBuilder. You can also use jconsole to find the ObjectName of the MBeans you want to manage.
Managing the broker using JMX is identical to management of any Java applications using JMX. It can be done by reflection or by creating proxies of the MBeans.
24.2.4.1. Configuring JMX Management 复制链接链接已复制到粘贴板!
By default, JMX is enabled to manage the broker. It can be disabled by setting jmx-management-enabled to false in broker.xml:
<jmx-management-enabled>false</jmx-management-enabled>
<jmx-management-enabled>false</jmx-management-enabled>
If JMX is enabled, the broker can be managed locally using jconsole.
Remote connections to JMX are not enabled by default for security reasons. Refer to Oracle’s Java Management Guide to configure the broker for remote management. System properties must be set in the artemis, or artemis.cmd for Windows installations, shell script located under INSTALL_DIR/bin.
By default, the broker uses the JMX domain "org.apache.activemq.artemis". To manage several brokers from the same MBeanServer, the JMX domain can be configured for each individual broker by setting jmx-domain in broker.xml:
<jmx-domain>my.org.apache.activemq</jmx-domain>
<jmx-domain>my.org.apache.activemq</jmx-domain>
24.2.4.2. MBeanServer Configuration 复制链接链接已复制到粘贴板!
When the broker is run in standalone mode, it uses the Java Virtual Machine’s Platform MBeanServer to register its MBeans. By default Jolokia is also deployed to allow access to the MBean server using REST.
24.2.4.3. Exposing JMX Using Jolokia 复制链接链接已复制到粘贴板!
The default Broker configuration ships with the Jolokia http agent deployed as a web application. Jolokia is a remote JMX over HTTP bridge that exposes MBeans. For more information see the Jolokia documentation.
To use Jolokia, the user must belong to the role defined by the hawtio.role system property in the BROKER_INSTANCE_DIR/etc/artemis.profile configuration file. By default, this role is amq. For more information about assigning a user to a role, see Section 9.2, “Adding Users”.
Example 24.1. Using Jolokia to Query the Broker’s Version
This example uses a Jolokia REST URL to find the version of a broker.
curl http://admin:admin@localhost:8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"0.0.0.0\"/Version
$ curl http://admin:admin@localhost:8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"0.0.0.0\"/Version
{"request":{"mbean":"org.apache.activemq.artemis:broker=\"0.0.0.0\"","attribute":"Version","type":"read"},"value":"2.4.0.amq-710002-redhat-1","timestamp":1527105236,"status":200}
The management queue is a special queue and needs to be instantiated directly by the client:
Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
To invoke management operations using JMS messages and the AMQ JMS client:
-
Create a
QueueRequestorto send messages to the management address and receive replies. -
Create a
Message. -
Use the helper class
org.apache.activemq.artemis.api.jms.management.JMSManagementHelperto fill the message with the management properties. -
Send the message using the
QueueRequestor. -
Use the helper class
org.apache.activemq.artemis.api.jms.management.JMSManagementHelperto retrieve the operation result from the management reply.
For example, to view the number of messages in the JMS queue exampleQueue:
The management address to send management messages is configured in the broker.xml file: <management-address>queue.activemq.management</management-address>
By default, the address is queue.activemq.management. The management address requires a special user permission type, manage, to be able to receive and handle management messages. This permission type is specified in the broker.xml file:
<security-setting-match="queue.activemq.management"> <permission-type="manage" roles="admin"/> </security-setting>
24.2.6. Management Notifications 复制链接链接已复制到粘贴板!
The broker sends notifications to inform listeners of events such as the creation of new resources, security violations, and other events.
There are two ways to receive these notifications:
- JMX notifications
- JMS messages
24.2.6.1. JMX Notifications 复制链接链接已复制到粘贴板!
If JMX is enabled (see Configuring JMX Management), JMX notifications can be received by subscribing to ObjectName org.apache.activemq.artemis:broker="BROKER_NAME".
24.2.6.2. Notification Types and Headers 复制链接链接已复制到粘贴板!
Below is a list of all the different kinds of notifications as well as which headers are on the messages. Every notification has a _AMQ_NotifType (value noted in parentheses) and _AMQ_NotifTimestamp header. The timestamp is the unformatted result of a call to java.lang.System.currentTimeMillis().
BINDING_ADDED(0)`_AMQ_Binding_Type`, `_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Binding_ID`, `_AMQ_Distance`, `_AMQ_FilterString`
`_AMQ_Binding_Type`, `_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Binding_ID`, `_AMQ_Distance`, `_AMQ_FilterString`Copy to Clipboard Copied! Toggle word wrap Toggle overflow BINDING_REMOVED(1)`_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Binding_ID`, `_AMQ_Distance`, `_AMQ_FilterString`
`_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Binding_ID`, `_AMQ_Distance`, `_AMQ_FilterString`Copy to Clipboard Copied! Toggle word wrap Toggle overflow CONSUMER_CREATED(2)`_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Distance`, `_AMQ_ConsumerCount`, `_AMQ_User`, `_AMQ_RemoteAddress`, `_AMQ_SessionName`, `_AMQ_FilterString`
`_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Distance`, `_AMQ_ConsumerCount`, `_AMQ_User`, `_AMQ_RemoteAddress`, `_AMQ_SessionName`, `_AMQ_FilterString`Copy to Clipboard Copied! Toggle word wrap Toggle overflow CONSUMER_CLOSED(3)`_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Distance`, `_AMQ_ConsumerCount`, `_AMQ_User`, `_AMQ_RemoteAddress`, `_AMQ_SessionName`, `_AMQ_FilterString`
`_AMQ_Address`, `_AMQ_ClusterName`, `_AMQ_RoutingName`, `_AMQ_Distance`, `_AMQ_ConsumerCount`, `_AMQ_User`, `_AMQ_RemoteAddress`, `_AMQ_SessionName`, `_AMQ_FilterString`Copy to Clipboard Copied! Toggle word wrap Toggle overflow SECURITY_AUTHENTICATION_VIOLATION(6)`_AMQ_User`
`_AMQ_User`Copy to Clipboard Copied! Toggle word wrap Toggle overflow SECURITY_PERMISSION_VIOLATION(7)`_AMQ_Address`, `_AMQ_CheckType`, `_AMQ_User`
`_AMQ_Address`, `_AMQ_CheckType`, `_AMQ_User`Copy to Clipboard Copied! Toggle word wrap Toggle overflow DISCOVERY_GROUP_STARTED(8)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow DISCOVERY_GROUP_STOPPED(9)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow BROADCAST_GROUP_STARTED(10)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow BROADCAST_GROUP_STOPPED(11)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow BRIDGE_STARTED(12)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow BRIDGE_STOPPED(13)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow CLUSTER_CONNECTION_STARTED(14)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow CLUSTER_CONNECTION_STOPPED(15)`name`
`name`Copy to Clipboard Copied! Toggle word wrap Toggle overflow ACCEPTOR_STARTED(16)`factory`, `id`
`factory`, `id`Copy to Clipboard Copied! Toggle word wrap Toggle overflow ACCEPTOR_STOPPED(17)`factory`, `id`
`factory`, `id`Copy to Clipboard Copied! Toggle word wrap Toggle overflow PROPOSAL(18)`_JBM_ProposalGroupId`, `_JBM_ProposalValue`, `_AMQ_Binding_Type`, `_AMQ_Address`, `_AMQ_Distance`
`_JBM_ProposalGroupId`, `_JBM_ProposalValue`, `_AMQ_Binding_Type`, `_AMQ_Address`, `_AMQ_Distance`Copy to Clipboard Copied! Toggle word wrap Toggle overflow PROPOSAL_RESPONSE(19)`_JBM_ProposalGroupId`, `_JBM_ProposalValue`, `_JBM_ProposalAltValue`, `_AMQ_Binding_Type`, `_AMQ_Address`, `_AMQ_Distance`
`_JBM_ProposalGroupId`, `_JBM_ProposalValue`, `_JBM_ProposalAltValue`, `_AMQ_Binding_Type`, `_AMQ_Address`, `_AMQ_Distance`Copy to Clipboard Copied! Toggle word wrap Toggle overflow CONSUMER_SLOW(21)`_AMQ_Address`, `_AMQ_ConsumerCount`, `_AMQ_RemoteAddress`, `_AMQ_ConnectionName`, `_AMQ_ConsumerName`, `_AMQ_SessionName`
`_AMQ_Address`, `_AMQ_ConsumerCount`, `_AMQ_RemoteAddress`, `_AMQ_ConnectionName`, `_AMQ_ConsumerName`, `_AMQ_SessionName`Copy to Clipboard Copied! Toggle word wrap Toggle overflow
24.2.7. Message Counters 复制链接链接已复制到粘贴板!
Message counters can be used to obtain information on queues over time as the broker keeps a history on queue metrics.
They can be used to show trends on queues. For example, using the management API, it would be possible to query the number of messages in a queue at regular intervals. However, this would not be enough to know if the queue is used: the number of messages can remain constant because nobody is sending or receiving messages from the queue or because there are as many messages sent to the queue than messages consumed from it. The number of messages in the queue remains the same in both cases but its use is widely different.
Message counters gives additional information about the queues:
countThe total number of messages added to the queue since the broker was started
countDeltaThe number of messages added to the queue since the last message counter update
messageCountThe current number of messages in the queue
messageCountDeltaThe overall number of messages added/removed from the queue since the last message counter update. For example, if
messageCountDeltais equal to-10this means that overall 10 messages have been removed from the queue (for example, 2 messages were added and 12 were removed)lastAddTimestampThe timestamp of the last time a message was added to the queue
udpateTimestampThe timestamp of the last message counter update
These attributes can be used to determine other meaningful data as well. For example, to know specifically how many messages were consumed from the queue since the last update simply subtract the
messageCountDeltafromcountDelta.
24.2.7.1. Configuring Message Counters 复制链接链接已复制到粘贴板!
By default, message counters are disabled as it might have a small negative effect on memory.
To enable message counters, you can set it to true in broker.xml:
<message-counter-enabled>true</message-counter-enabled>
<message-counter-enabled>true</message-counter-enabled>
Message counters keeps a history of the queue metrics (10 days by default) and samples all the queues at regular interval (10 seconds by default). If message counters are enabled, these values should be configured to suit your messaging use case in broker.xml:
<!-- keep history for a week --> <message-counter-max-day-history>7</message-counter-max-day-history> <!-- sample the queues every minute (60000ms) --> <message-counter-sample-period>60000</message-counter-sample-period>
<!-- keep history for a week -->
<message-counter-max-day-history>7</message-counter-max-day-history>
<!-- sample the queues every minute (60000ms) -->
<message-counter-sample-period>60000</message-counter-sample-period>
Message counters can be retrieved using the Management API. For example, to retrieve message counters on a JMS queue using JMX: