Message Queue in C# : Priority

T

tiger

Hi,

I have a question on Microsoft Message Queue. How do I give higher priority
to messages and get it process before others. I will like to use the
mechanism supplied by the queue service rather than relying on reading all
the messages and ordering them. Below I have a simple send and receive.

System.Messaging.Message msg = new System.Messaging.Message();
msg.Body=myPayment;
MessageQueue msgQ =new MessageQueue(".\\Private$\\billpay");
msgQ.Send(msg);
msgQ.Formatter = new XmlMessageFormatter(arrTypes);
myPayment=((Payment)msgQ.Receive().Body);

Your assistants will be greatly
appreciated.

ThanksTiger
 
N

Nicholas Paldino [.NET/C# MVP]

tiger,

You can set the Priority property of the message to a priority, but it's
not very granular.

The only way to really handle this is to read the messages from the
queue as they come in, and then process them in the order that you want.
MSMQ doesn't really guarantee order.

What you might want to do is store the ids of the messages as you send
them. On the server side, you would read the messages and store them, along
with their ids. Then, on the client, when you know you have sent the
messages, you send another message indicating which messages to process (and
possibly order).

Of course, this means that you will have to wait until all of those
messages come in to process.

This makes me think that your approach could be improved upon. Instead
of sending all of these messages which require specific ordering, why not
just send ONE message which has the tasks that need to be performed, and
have the server process that?

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top