Getting Message by priority from MSMQ

与世无争的帅哥 提交于 2019-11-29 14:13:19

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1310414/getting-message-by-priority-from-msmq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!