5 Replies Latest reply on Feb 3, 2009 9:31 AM by Tim Fox

    discarding consumer messages.

    Andy Taylor Master

      This is regarding https://jira.jboss.org/jira/browse/JBMESSAGING-1214.

      If you consider the example where a consumer is receiving messages regarding a stock price then these messages are transitory. The consumer is only really interested in the newest messages. If the consumer is slow then these messages could build up and the information being received out of date. It should be possible to set the max number of messages to keep.

      My first thought is to do this in the server consumer. during the handle method if maxNumberOfMessages is set we check how many messages the queue has and if greater we we pre ack the message without delivering and return handled. The one thing I'm not sure of is how this would work with filters since only a subset of the queue may be destined for this consumer. thoughts?

        • 1. Re: discarding consumer messages.
          Tim Fox Master

          It's easier and more efficient to reject messages at the server and not the client.

          What need is a header in a message HDR_SOLO_MESSAGE (or whatever).

          I sent a stock price to the queue and set the HDR_SOLO_MESSAGE to the stock ticker symbol e.g. RHT.

          When the queue receives the message, it checks to see if HDR_SOLO_MESSAGE is present, if so, it looks in its local map to see if there is already a message in the queue with the same value of HDR_SOLO_MESSAGE.

          If not, then it just adds the message as normal to the queue as normal. If so, then it removes the older reference with that header value before adding it.

          In such a way there will only be the latest message for each stock ticker value in the queue at any time. I.e. only the latets price would be available.

          This can be done by subclassing QueueIpl and adding the map and extra check on routing.

          • 2. Re: discarding consumer messages.
            Andy Taylor Master

            Ok, that makes sense.

            I guess the we just add a new queue setting and the queuefactory can make the correct kind of queue needed.

            • 3. Re: discarding consumer messages.
              Fran├žois Duchatelet Newbie

              Shouldn't we use the TTL for that ?

              Say, put a TTL of the lentgh of validity period for the stock price.

              That way, if the consumer is slow, old (outdated) messages are discarded, leaving only the fresh ones in the queue.

              François

              • 4. Re: discarding consumer messages.
                Andy Taylor Master

                that assumes that the rate these messages are sent are consistent and you know what the interval is. You wouldn't want to delete a message if a replacement hadn't arrived and vice versa you wouldn't want to keep a message even tho a newer one had arrived but the TTL hadn't. expired

                • 5. Re: discarding consumer messages.
                  Tim Fox Master

                   

                  "gozilla" wrote:
                  Shouldn't we use the TTL for that ?

                  Say, put a TTL of the lentgh of validity period for the stock price.

                  That way, if the consumer is slow, old (outdated) messages are discarded, leaving only the fresh ones in the queue.

                  François


                  Sure, nothing is stopping you setting a TTL on the message, that will work too, if that's what you want.

                  However the semantics of this are slightly different as Andy mentioned.