6.4. Management operations
Whether you are using JMX or JMS messages to manage AMQ Broker, you can use the same API management operations. Using the management API, you can manage brokers, addresses, and queues.
6.4.1. Broker management operations 링크 복사링크가 클립보드에 복사되었습니다!
You can use the management API to manage your brokers.
- 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().- 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.- Enabling and resetting message counters
Enable and disable message counters using the
enableMessageCounters()ordisableMessageCounters()method.Reset message counters by using the
resetAllMessageCounters()andresetAllMessageCounterHistories()methods.- 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).- 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)참고Because this method actually stops the broker, you will likely receive an error. The exact error depends on the management service you used to call the method.
6.4.2. Address management operations 링크 복사링크가 클립보드에 복사되었습니다!
You can use the management API to manage addresses.
Manage addresses using the AddressControl class with 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() or removeRole() methods. You can list all the roles associated with the queue with the getRoles() method.
6.4.3. Queue management operations 링크 복사링크가 클립보드에 복사되었습니다!
You can use the management API to manage queues.
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 are sent to this address, otherwise they are discarded. You can define the expiry address for an address or set of addresses (and hence the queues bound to those addresses) in theaddress-settingselement of thebroker.xmlconfiguration file. For an example, see the "Default message address settings" section in Understanding the default broker configuration.Send messages to a dead letter address using the
sendMessagesToDeadLetterAddress()method. This method returns the number of messages sent to the dead letter address. If a dead letter address is defined, messages are sent to this address, otherwise they are removed from the queue and discarded. You can define the dead letter address for an address or set of addresses (and hence the queues bound to those addresses) in theaddress-settingselement of thebroker.xmlconfiguration file. For an example, see the "Default message address settings" section in Understanding the default broker configuration.Move messages from one queue to another using the
moveMessages()method.- 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 6.6절. “Using message counters”). 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.
6.4.4. Remote resource management operations 링크 복사링크가 클립보드에 복사되었습니다!
You can use the management API to start and stop a broker’s remote resources (acceptors, diverts, bridges, and so on) so that the broker can be taken offline for a given period of time without stopping completely.
- 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. - 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 Broker discovery methods 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 Broker discovery methods 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 Creating a broker cluster for more information.