简体   繁体   English

如何在MSMQ中更改消息的优先级?

[英]How can I change the priority of a message in MSMQ?

I'm having a problem changing the priority of an message which is submitted to a defined MSMQ. 我在更改提交给已定义的MSMQ的消息的优先级时遇到问题。 Whenever I set the Message priority it never seems to affect the priority of the message within the queue Here is a snipet of what I am doing: 每当我设置消息优先级时,它似乎永远不会影响队列中消息的优先级。这是我正在做的事情的狙击:

static public void QueueBatchItem(MessageQueue mq, MessageQueueTransaction msgTx, MessagePriority msgPriority)
{
    using (System.Messaging.Message mm = new System.Messaging.Message())
    {
        string messageLabel = Guid.NewGuid().ToString();
        System.Messaging.XmlMessageFormatter formatter = new XmlMessageFormatter();

        RunSimulationRequestDTO dto = new RunSimulationRequestDTO();
        dto.RetryCount = 0;
        dto.BatchHeaderID = batchID;
        dto.MSMQLabel = messageLabel;

        mq.MessageReadPropertyFilter.Priority = true;
        mm.Priority = msgPriority;

        mm.Body = dto;
        mm.Label = messageLabel;
        mm.Formatter = formatter;
        mq.Send(mm, msgTx);

    }
}

If I debug thru the code the default priority is 'Normal' and when an item is sent to the queue the priority shows up as 0 with 'Queue messages'. 如果我通过代码进行调试,则默认优先级为“正常”,当项目发送到队列时,优先级显示为“队列消息”为0。 I can pass over the priority as MessagePriority.High or any of the 8 possible values and it never changes what the priority is. 我可以将优先级作为MessagePriority.High或8个可能值中的任何一个传递,并且它永远不会更改优先级。

What am I missing in this... the few examples that I've seen have all shown things has basic as 我在这里错过了什么...我见过的几个例子都是基本的

Message mm = new Message();
mm.Priority = MessagePriority.High;

I've even tried just little test apps outside of my main code with the MSDN examples and the priority number never changes. 我甚至尝试过使用MSDN示例在主代码之外的小测试应用程序,优先级编号永远不会改变。

thanks. 谢谢。

edit: I made sure that the priority I was seeing was not coming from the thread by setting it to AboveNormal 编辑:我确保我看到的优先级不是来自线程,通过将其设置为AboveNormal

  <ThreadManagersConfiguration DefaultSleepBetweenPolls="5000" DefaultMsmqServer=".">
    <ThreadManagers>
      <add DisplayName="BatchSimulationManager" 
           RequestMSMQ=".\Private$\BatchSimulationRequest" 
           ResponseMSMQ="" 
           FailedMSMQ=".\Private$\BatchSimulationFailure" 
           Priority="AboveNormal" 
           TransactionalMode="RollbackTransaction" 
           MaxThreads="16" 
           SleepTimeBetweenPolling="10000" 
           ProcessModel="BATCH"/>
    </ThreadManagers>
  </ThreadManagersConfiguration>

队列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM