从MSMQ按优先级获取消息 [英] Getting Message by priority from MSMQ

查看:191
本文介绍了从MSMQ按优先级获取消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过设置MSMQ的优先级来发送消息.使用C#

我可以先从具有高优先级的MSMQ获得消息吗?

就像我们进入优先队列一样.

还有一件事..

假设有三个优先级

0-高 1-中 2-低

队列中的顺序为2001122221111100

现在是否发送高优先级(0)的消息?通过在MSMQ中设置优先级.会像实际的优先级队列"一样显示吗?

解决方案

MSMQ确实支持消息的优先级排队,但是具有相同优先级的消息在出队时按到达顺序进行处理.例如,如果您发送3条消息,其中两条优先级为7,一条优先级为0,则将接收到的优先级为7的第一条消息出队,然后接收优先级为7的第二条消息,最后是该消息优先级0.您不必执行任何特殊处理即可按优先级顺序处理排队的消息……但是,请注意,任何给定优先级的最旧"消息将在相同优先级的最新"消息之前出队.还应注意,任何事务性消息都会忽略其优先级IIRC.

尽管MSMQ支持优先级,但它的行为并不完全像优先级队列.两者是不同的算法,而MSMQ则要复杂得多.设置邮件的优先级后, help 不仅会确定该邮件的出队顺序,还会影响该邮件通过发件人/用户通过MSMQ服务传播的优先级.发布者到接收者/订阅者.假设您使用三个最低优先级(MSMQ支持8个优先级,从0(最低)到7(最高)),则可能会发生以下情况:

0 =低,1 =中,2 =高

发件人在指定的时间(分钟:秒)发送具有给定优先级的邮件:

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

收件人按照以下顺序在其队列中排队消息(假定没有消息出队):

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

当您处理来自接收者队列的消息时,将按照优先级顺序和接收时间对消息进行处理.

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?

解决方案

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.

这篇关于从MSMQ按优先级获取消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆