Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Message by priority from MSMQ

i am sending messages in MSMQ by setting its priority. using C#

can i get the message from MSMQ having high priority first?

just like we get in Priority Queue.

and one thing more..

suppose there are three priority level

0 - high 1- medium 2 - low

the sequence in queue is 2001122221111100

now if i send message with high priority(0) where it will be placed?? by setting priority in MSMQ. will it behave like actual Priority Queue?

like image 941
Mohsan Avatar asked Aug 21 '09 07:08

Mohsan


People also ask

What is message priority in MQ?

You set the priority of a message (in the Priority field of the MQMD structure) when you put the message on a queue. You can set a numeric value for the priority, or you can let the message take the default priority of the queue.

What is priority message?

A category of precedence reserved for messages that require expeditious action by the addressee(s) and/or furnish essential information for the conduct of operations in progress when routine precedence will not suffice. See also precedence. Dictionary of Military and Associated Terms.

Is MSMQ asynchronous?

Asynchronous messaging. With MSMQ asynchronous messaging, a client application can send a message to a server and return immediately, even if the target computer or server program is not responding.

How does RabbitMQ priority work?

The priority of each message is specified when the message is published to the queue. Larger numbers indicate higher priority, and messages with higher priority will be delivered before messages with less priority. Publishers specify message priority using the priority field in message properties.


1 Answers

MSMQ does support priority queuing of messages, however messages of the same priority are handled in order of arrival when dequeued. For example, if you send 3 messages, two of priority 7 and one of priority 0, then the first message of priority 7 that was received will be dequeued, followed by the second message of priority 7 that was received, finally followed by the message priority 0. You should not have to do anything special to process queued messages in their priority order...however just be aware that the "oldest" message of any given priority will be dequeued before the "newest" message of the same priority. It should also be noted that any transactional messages ignore their priority, IIRC.

EDIT:

While MSMQ supports priorities, it will not behave exactly like a priority queue. The two are different algorithms, with MSMQ being significantly more complex. When you set the priority of a message, not only does that help determine the order in which that message will be dequeued, it also affects the priority at which that message will propagate through the MSMQ service from sender/publisher to receiver/subscriber. Assuming you use the three lowest priorities (MSMQ supports 8 priorities, from 0 (lowest) to 7 (highest)), the following scenario might occur:

0 = low, 1 = medium, 2 = high

Sender sends messages with the given priorities at the specified times (minute:second):

0 @ 1:00  
2 @ 1:00
0 @ 1:01
1 @ 1:02
1 @ 1:03
0 @ 2:01
2 @ 2:01

Receiver queues up messages in its queue in the following order (assuming no messages are dequeued):

2 @ 1:00
2 @ 2:01
1 @ 1:02
1 @ 1:03
0 @ 1:00
0 @ 1:01
0 @ 2:01

When you process messages from the receiver's queue, they will be processed in both order of priority, as well as the time received.

like image 148
jrista Avatar answered Sep 21 '22 13:09

jrista