3 Replies Latest reply on Oct 8, 2003 4:04 AM by edelarosa

    Delete messages from queue

    parthi_10

      Hi,

      I have created a queue by adding an entry in the Jbossmq-destinations.xml. Now I start the class which sends the messages to the queue and then i start the class which reads messages from tat queue. Now if i stop the class which reads the messages from the queue, the messages get accumulated in the queue. Now i shut down the jboss server. What happens is tat the messages will still remain in the queue. When i restart the jboss server and the reader class i m able to read the messages from the queue. Now i want to delete the messages in the queue if the appserver is shut down. How do i do this?? Is there any parameter which has to be set in the xml file to do this??

      Thanks and Regards
      Parthiban

        • 1. Re: Delete messages from queue
          genman


          You can delete the messages in the queue through JMX upon startup or shutdown. Or, if you don't want the messages saved at all, call "setDeliveryMode" on the QueueSender with the value "DeliveryMode.NON_PERSISTENT"

          References:

          http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/MessageProducer.html#setDeliveryMode(int)
          http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/DeliveryMode.html#NON_PERSISTENT

          • 2. Re: Delete messages from queue

            If you locate the queue on
            http://localhost:8080/jmx-console
            it is in jboss.mq.destinations unless you changed the mbean
            name.

            There is a removeAllMessages() operation.

            Regards,
            Adrian

            • 3. Re: Delete messages from queue
              edelarosa

              Hi Parthi,

              Just a quick solution without using jmx-console or changing code:

              Jboss uses hypersonic db as persistent storage for serialized jms
              messages. We may prefer to preserve the default setting for Queues
              or Topics to be persistent now because that is a good idea (don't
              lose your messages).

              The hypersonic database is set up by Jboss during its first run.
              The original database/table structure resides in a flat file named "default.script". This file contains only 73 lines declaring
              the database structure. Copy the first 73 lines to a backup file, say
              "default.bak".

              If by scenario, you ran your application and spawned some
              messages to the queue without any dequeuer or consumer,
              definitely your message will pile-up over your Queue.

              To discard all serialized messages on the Queue, you may
              stop JBoss, overwrite the "default.script" with your "default.bak".

              When you run your JBoss again, you'll never see any serialized
              messages on the Queue being consumed by MDB (if any).

              Finally, you may find the "default.script" file under your:

              $JBOSS_HOME/server/default/data/hypersonic folder.

              cheers!