1 Reply Latest reply on Apr 14, 2009 4:23 AM by Yong Hao Gao

    Message selector and consuming messages

    Vikas Gupta Newbie

      Hello Everyone,

      We have a requirement of two queues. One primary and other secondary i.e. if a message can be processed immediately, it is sent to primary queue else it is sent to secondary queue. Both queues are consumed by different MDBs and all transactions work in container transaction.

      For primary queue consumer MDB say P_mdb the processing is straight forward as the messages are consumed right away. But for secondary queue consumer MDB say S_mdb we need to limit the processing on the basis of flag. Thus as message selector we use a flag with value Y for this S_mdb. Thus messages with flag having value Y will be processed. Now when we want to send message to secondary queue we send message with flag as N. Thus message is sent to queue but not processed. But when we want to process this message, we browse through secondary queue and set the flag as Y to the message read from the queue, thus making it eligible for processing by S_mdb.

      We want to know whether this approach is correct or there is other way to explicitly process subset of messages already present on queue i.e. selective processing. We do not want that message sent to queue to be processed right away but we want that we can have a control on which all messages can be processed i.e. consumed at later point of time. The method receive, receive (time), and receiveNoWait does not work for us as they do not give assurance that the message will be processed within the time limit of ongoing container transaction. That’s why we introduced S_mdb.

      Though this approach works but we see that messages are processed only on high load for secondary queue by S_mdb otherwise the messages remain on the queue despite of changing their flag and not sent to S_mdb for consumption (waited for couple of hours!). That’s why I have raised the above question.

      Best Regards,
      Abhishek

        • 1. Re: Message selector and consuming messages
          Yong Hao Gao Master

          Hi Abhishek,

          The messages in a queue will be delivered right away if there is any active consumers. However, if the messages are 'rejected' by the selector and go back to queue, they won't get delivered again if the consumer remains the same. So for your case, I suggest you can have your consumer to be configurable in some way, or have a new consumer for each selector. for example:

          you create a consumer with selector that only consumes messages with flag Y.
          after some time you need message with N, you can dynamically create a consumer with selector N and consume the messages.