Empty a jms queue in JBOSS 7 using HornetQ

10,920

All you have to do is to call the method:

from the jboss-cli:

/subsystem=messaging/hornetq-server=default/jms-queue=testQueue:remove-messages

I just tried at the exact versions you tried by adding a large ammount of messages, including with paging.. and everything worked fine.

I configured my system to page, and used this to create a few thousand messages:

  HornetQConnectionFactory cf = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(NETTY_CONNECTOR_FACTORY));
  Connection conn = cf.createConnection("guest", "hello");
  Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
  javax.jms.Queue queue = sess.createQueue("testQueue");
  MessageProducer prod = sess.createProducer(queue);

  for (int i = 0 ; i < 50000; i++)
  {
     TextMessage msg = sess.createTextMessage("hello " + i);
     prod.send(msg);
     if (i % 500 == 0)
     {
        System.out.println("Sent " + i);
        System.out.println("commit");
        sess.commit();
     }
  }
  sess.commit();
  conn.close();

I then tried the remove method and it worked:

/subsystem=messaging/hornetq-server=default/jms-queue=testQueue:remove-messages

If this is not working there are two possibilities:

  • We changed how the locks are held on the queue during delivery. Perhaps you are hitting a fixed bug and you would have to move to a newer version.

  • You have queues in delivery on consumers. We can't delete messages if they are on the Consumer's buffer in delivery state. You would have to remove consumers to delete all messages.

I'm adding this answer here as I did a lot of research trying to replicate your issue and everything worked like a charm. I would need more information to what's going.

I think the best would be the user's forum where we can discuss it further. SOF is going to simple questions / answer. It's not a place for investigating bugs or anything like that.

https://community.jboss.org/en/hornetq?view=discussions

Share:
10,920
Leonardo Porto
Author by

Leonardo Porto

Updated on July 19, 2022

Comments

  • Leonardo Porto
    Leonardo Porto almost 2 years

    I am using jboss 7.1.1 final and HornetQ 2.2.13 final.

    I have a couple of queues configured and one of them is "full" of messages, couple of thousands. I cant delete the messages.

    Ive tried deleting them using jboss cli with the command /subsystem=messaging/hornetq-server=default/jms-queue=Queue:remove-messages

    it responds with success, but the messages are still there...

    Ive tried deleting them using JConsole with a jmx command. It responds with the number zero and the count messages are still the same.

    Ive tried deleting the queue inside Jboss Console and restarting the AS. After I configure the queue again, the messages are still there cause its persisted.

    The only way it worked was configuring hornetq server to disable persistence inside standalone.xml.

    Does anybody know how to do it using jconsole or jboss cli?

  • Leonardo Porto
    Leonardo Porto over 10 years
    Was persistence enabled on your test? anyways... this is the answer I found for my problem: community.jboss.org/thread/197030?start=0&tstart=0
  • Clebert Suconic
    Clebert Suconic over 10 years
    Yes.. Persistence was enabled. I'm basically using the method Jaikiran provided on his answer. You just have to call remove-messages and it should work
  • Leonardo Porto
    Leonardo Porto over 10 years
    Check out Justin Bertram's answer below Jaikiran's answer.
  • Leonardo Porto
    Leonardo Porto over 10 years
    It doesnt matter if you delivered 15k messages to the queue, all of them will have their status changed to "in delivery" right way and you cant delete them. I wanted to change that for my test environment where I make stress tests all the time.
  • Clebert Suconic
    Clebert Suconic over 10 years
    You can't delete a message that's in delivery. That would lead to duplicates.. the message stays at the client... we can't delete it. It's part of the caveat of a messaging system.
  • iskramac
    iskramac about 8 years
    You can also try to decrease number of messages "in delivery" by disabling buffering of messages on client side. This can be done by setting "consumer-window-size" in connection-factory configuration. Although that might impact consuming performance.