This article describes the activemq message cleaning method:
- Placement method
- Command Line
What is the difference between purge and delete
We see purge and delete in the queue of the management interface, and note that only the queue has purge .
The difference is simple:
purge
: Just clear the message in the queue and put the message into the queuedelete
: Delete this queue, it will disappear in the list
Why should I delete the expired queue or topic?
Because, if you do not delete not only take up space, but too much accumulation will cause the management interface to freeze.
By configuring regular cleaning
Official documentation: http://activemq.apache.org/delete-inactive-destinations
The configuration has the following:
schedulePeriodForDestinationPurge="60000"
, Which means clean up every 60 seconds, the default is 0gcInactiveDestinations="true"
, On behalf of recycling inactive targets, the default is falseinactiveTimeoutBeforeGC="30000"
, When the target limit is deleted for 30 seconds, the default is 60 seconds
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" useJmx="true"
dataDirectory="${activemq.data}" schedulePeriodForDestinationPurge="60000">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" >
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="1000"/>
</pendingMessageLimitStrategy>
</policyEntry>
<policyEntry queue=">" gcInactiveDestinations="true" inactiveTimeoutBeforeGC="30000"/>
</policyEntries>
</policyMap>
</destinationPolicy>
Example results:
2020-04-07 16:09:16,619 | INFO | 0c2f8e32-3a4b-449a-807f-086012425188 Inactive for longer than 30000 ms - removing ... | org.apache.activemq.broker.region.Queue | ActiveMQ Broker[localhost] Scheduler
2020-04-07 16:09:16,620 | INFO | b3004cb2-d625-44e3-b18a-33e857a6b69d Inactive for longer than 30000 ms - removing ... | org.apache.activemq.broker.region.Queue | ActiveMQ Broker[localhost] Scheduler
2020-04-07 16:09:16,621 | INFO | 32d7e194-15ba-458b-a4f9-91a41d37fb32 Inactive for longer than 30000 ms - removing ... | org.apache.activemq.broker.region.Queue | ActiveMQ Broker[localhost] Scheduler
2020-04-07 16:09:16,622 | INFO | 8ffa6724-0ec9-4128-93bb-0955e0066a8c Inactive for longer than 30000 ms - removing ... | org.apache.activemq.broker.region.Queue | ActiveMQ Broker[localhost] Scheduler
Command line cleanup
purge is cleaning, such as cleaning all or part of a queue
# bin/activemq purge 00015a7f-5bc4-4a76-aab3-366dee279320
...
INFO: Purging all messages in queue: 00015a7f-5bc4-4a76-aab3-366dee279320
Regular match deletion: You can selectively clean up certain queue / topic messages that meet the conditions:
Examples:
Main purge FOO.BAR
- Delete all the messages in queue FOO.BAR
Main purge --msgsel "JMSMessageID='*:10',JMSPriority>5" FOO.*
- Delete all the messages in the destinations that matches FOO.* and has a JMSMessageID in
the header field that matches the wildcard *:10, and has a JMSPriority field > 5 in the
queue FOO.BAR.
SLQ92 syntax is also supported.
* To use wildcard queries, the field must be a string and the query enclosed in ''
Use double quotes "" around the entire message selector string.
For example: clean up the queue news starting at 000
# bin/activemq purge 000*
I didn't find the delete function on the command line. It can be removed regularly through the above configuration.