Reading a message from a queue

I was wondering if it is possible to read a message that is in the queue without taking it out of the queue?

When we call " mq_receive() " message is removed from the queue, but I dont want to remove it from the queue just yet. The reason, it is possible that my process may not have resources to process that specific message yet.



As far as I know there is no way to ‘peek’ at the message queue to see what’s there.

I have to ask the question why your program would try to read a message if it didn’t have the resources to process it. Or are you saying some messages require more resources than others?

Alternatively, if your program reads a message and it doesn’t have enough resources just buffer the message internally until you do have the resources and don’t read anything further from the queue until the buffered message is processed.


Or, write your own message queue hander with this feature, or get the source and add the feature.

… or put it back on the queue, inefficient; but if using message queues, efficiency obviously isn’t a concern…

If this will help I use a perl script to scan the frozen messages and unfreeze the valid ones if required. It is quite a manual process but it seems to work ok for me.