3

I have several jobs that each have multiple messages queued. The messages for each job are randomly interleaved. If a user decides to cancel a job I want to remove all the messages that are part of that job from the queue. I have been able to use browse()to find all the messages to remove but haven't been able to figure out how to remove them. I tried getting rid of them by using receiveSelected() but it just hangs. (I am using JmsTemplate)

Solx
  • 4,611
  • 5
  • 26
  • 29

3 Answers3

0

JMS does not define administration type functions, such as deleting a message from the queue.

The programmatic way is to consume the message. Alternatively, there are messaging management tools that allow you to do this without programming.

Matt Pavlovich
  • 4,087
  • 1
  • 9
  • 17
0

There is no any JMS API to remove message. However seems you can invoke purge removeMessage or other operation as per your requirement on MBean org.apache.activemq:type=Broker,brokerName=amq,destinationType=Queue,destinationName=testQ to delete messages.

Varsha
  • 1,150
  • 9
  • 12
0

You are on the right track. Consuming those messages using a selector is the way to go - such as with JmsTemplate receiveSelected.

If it "hangs", it likely means you have no matching messages on the queue. Can you identify your messages on some Property, such as JMSType or other StringProperty? Make sure you can and supply a JMS Selector.

I.e. if your jobs are initiated by user X, then set some property such as "initiatingUser" to "x". Then to consume all messages, use the selector initiatingUser='X'.

Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • I don't understand why browse finds the message, but select hangs. I am using the same messageSelector string in both cases and the same destinationName. – Solx Aug 01 '17 at 18:02
  • I am browsing with `jmsTemplate.browseSelected` and selecting with `jmsTemplate.receiveSelected(` – Solx Aug 01 '17 at 18:04