Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

msmq

I'm having a problem changing the priority of an message which is submitted to a defined 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'. I can pass over the priority as MessagePriority.High or any of the 8 possible values and it never changes what the priority is.

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.

thanks.

edit: I made sure that the priority I was seeing was not coming from the thread by setting it to 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>

queue

like image 747
Christopher Klein Avatar asked Nov 21 '11 14:11

Christopher Klein


1 Answers

Easy one, this:

“Why do transactional messages all have the same priority?”

http://geekswithblogs.net/Plumbersmate/archive/2011/02/03/ldquowhy-do-transactional-messages-all-have-the-same-priorityrdquo.aspx

like image 75
John Breakwell Avatar answered Oct 15 '22 22:10

John Breakwell