按优先级从 MSMQ 获取消息
我通过设置优先级在 MSMQ 中发送消息。使用 C#
我可以首先从 MSMQ 获取具有高优先级的消息吗?
就像我们进入优先队列一样。
还有一件事..
假设有三个优先级
0 - 高 1- 中等 2 - 低
队列中的序列是 2001122221111100
现在如果我发送具有高优先级(0)的消息,它将被放置在哪里?通过在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSMQ 确实支持消息的优先级排队,但是相同优先级的消息在出队时按到达顺序进行处理。例如,如果您发送 3 条消息,其中两条优先级为 7,一条优先级为 0,则接收到的第一条优先级 7 的消息将出列,然后是接收到的第二条优先级 7 的消息,最后是接收到的优先级 7 的消息。优先级 0。您不必执行任何特殊操作来按优先级顺序处理排队消息...但是请注意,任何给定优先级的“最旧”消息将在相同优先级的“最新”消息之前出列。还应该注意的是,任何事务性消息都会忽略它们的优先级 IIRC。
编辑:
虽然 MSMQ 支持优先级,但它的行为与优先级队列并不完全相同。两者是不同的算法,MSMQ 要复杂得多。设置消息的优先级时,不仅帮助确定该消息出列的顺序,还会影响该消息通过 MSMQ 服务从发送者/处传播的优先级。发布者到接收者/订阅者。假设您使用三个最低优先级(MSMQ 支持 8 个优先级,从 0(最低)到 7(最高)),则可能会出现以下情况:
0 = 低、1 = 中、2 = 高
发件人发送具有给定优先级的消息指定的时间(分钟:秒):
接收方按以下顺序在其队列中排队消息(假设没有消息出列):
当您处理来自接收方队列的消息时,它们将按优先级顺序和优先级顺序进行处理收到的时间。
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):
Receiver queues up messages in its queue in the following order (assuming no messages are dequeued):
When you process messages from the receiver's queue, they will be processed in both order of priority, as well as the time received.