1
votes

I am coding with c# and activemq, using NMS and apache-activemq-5.9.1.I want to set a unique guid in custom property for each message when I send it, then I can delete a specific message with by its guid(NOT purge a queue, only delete one message in it). I found similar question in Can I delete a message from a queue of ActiveMQ in c# code?, but it has no answer so i ask again.

1

1 Answers

2
votes

There only two things you can do with the NMS API in this regard. The first is to delete the entire destination as shown in the referenced question.

The second is to use a consumer that has a selector assigned that will match only the message you want to discard. The consumer would receive and ACK the message which would remove it from the broker. This works only when the Queue depth is no so great that the message is stored in the Message store and will not be paged in due to the maxPageSize setting in ActiveMQ not being large enough.

The only other solution is to use the REST API provided by Jolokia to access the ActiveMQ MBeans and attempt to remove the message that way however you can still run into the issue of the message being in offline storage and not being able to be paged in for removal.

The root problem here is that you are trying to use ActiveMQ as a database, which it (or any other JMS broker) is not intended to be. This is an anti-pattern that comes up quite often. If you want to access messages in a DB way, then use a DB, you'll save yourself a great deal of time and effort.