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

1

6

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

Mercaptide answered 21/11, 2011 at 14:42 Comment(2)
Is this a queue private to your application?Overvalue
You are definitely looking at the message priority and not the queue priority, which has a default value of 0Overvalue
D
4

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

Dendrite answered 21/11, 2011 at 18:29 Comment(1)
Thanks. I never associated the problem with the message/queue type. App doesn't work as non-transactional so I guess I need to find another way to do what I need to do.Mercaptide

© 2022 - 2024 — McMap. All rights reserved.