6 Replies Latest reply on Nov 13, 2003 5:15 AM by Stephane Nicoll

    Message Scheduled Delivery cancellation

    sanjewad Newbie

      Hi

      I am queuing some messages with a scheduled delivery feature implemented in JBoss 3.2.2. Now If I want to cancel/remove a particular message before it get consumed is it possible me to remove that from the queue?

      Is this remove feature implemented or not ?

        • 1. Re: Message Scheduled Delivery cancellation
          Stephane Nicoll Master

          It has nothing to do with scheduling as far as I know. If you want to remove a message just consume it (But you need to identify the message in some way)

          See http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=

          • 2. Re: Message Scheduled Delivery cancellation
            sanjewad Newbie

            My client wants to activate a service say 7 days from now. So I send a message with a scheduled delivery to activate 7 days from now. But for some reason the client says to cancel that activation.

            Isn't it better to remove the message before it get consumed?

            I prefer this rather than checking the message ID and then say not to activate.

            • 3. Re: Message Scheduled Delivery cancellation
              Stephane Nicoll Master

              This is not what I suggested. To remove the message you have to identify, right? Otherwise how can you say 'I want to remove that message because the client wants to cancel something''.

              I wasn"t saying 'check the ID and say do not activate. I was saying "please JMS give the message ID blablabla' and instead of doing something with it, just forget about it and close the session (that will have as effect that the message will be removed from the queue).

              I don't understand why this concept is so difficult to understand. If you want to remove A message, you need a way to identify it, right? So you need, either the JMSMessageID, either your own ID mechanism, put as a JMS header (see my previous link for full details).

              Is it clear?

              Regards,

              Stephane

              • 4. Re: Message Scheduled Delivery cancellation
                sanjewad Newbie

                Can you please post an example that you have already worked out with MDB.
                -----------------

                If you have a queue with orders and MDB connected on it. And if you want to cancel an order (that is remove a message) like this, it has basically no sense. Except when you server is highly loaded, the message will be processed almost immediatly. What's the purpose of cancelling an order if you need to do it in the next 5 seconds?

                But I cannot agree with this for Scheduled Delivery.
                Since there may be a possibility of deleting messages before it got received?.

                • 5. Re: Message Scheduled Delivery cancellation
                  Stephane Nicoll Master

                  >But I cannot agree with this for Scheduled Delivery.
                  >Since there may be a possibility of deleting >messages before it got received?.

                  Schedule delivery is just a message sitting in the queue and waiting for the delivery time. If you want to cancel this message, just 'receive' it manually. That is create a receiver to receive only that message (using a selector) and that 's it.

                  Something like:

                  if (action.getAction().getType().equals(Action.Type.CANCEL)) {
                  logger.info("Cancelling notification with ID [" + action.getNotificationID() + "]");

                  String selector = Constants.NOTIFICATION_ID_PROPERTY + " = '" + action.getNotificationID() + "'";
                  JmsReceiverLocal jmsReceiver = JmsReceiverUtil.getLocalHome().create();
                  Message m = jmsReceiver.receive(notificationQueue, selector);

                  if (m == null) {
                  logger.warn("no notification with ID [" + action.getNotificationID() + "] was found");
                  } else {
                  logger.info("Notification with ID [" + action.getNotificationID() + "] canceled successfully");
                  }

                  // send response
                  } else {
                  logger.error("Action [" + action.getAction() + "] not yet supported");
                  }

                  Where notificationID is a ID I set on the message (it could be JMSMessageID, in that case you don't have to set anything, just to keep a reference of the message somewhere)

                  Regards,

                  Stephane

                  • 6. Re: Message Scheduled Delivery cancellation
                    Stephane Nicoll Master

                    > Can you please post an example that you have already worked out with MDB.

                    Mmmm I start understanding why you do not understand ... Your MDB is there to get fired with a message (let's say in 7 days). If some component before that period consume the message, your mdb will not be fired (so your component cancel the message, right?)

                    What you need is a Session Bean that creates a receiver and the receive and consume that message. (see code snipper above - JmsReceiverSessionBean is a bean that can fetch data in a queue using a selector).

                    Regards,

                    Stephane