2

I writing a console app that add a message to local queue. But, no message is being inserted.

I created the queue as transactional and inserting like following:

      string path = @"FormatName:DIRECT=OS:computername\private$\myqueue";
        MessageQueue queue = new MessageQueue();
        queue.Path = path;            

        foreach (string msg in messages)
        {
            queue.Send("inputMessage", msg);

        }

Anything wrong with this?

Thanks.

Tony
  • 3,319
  • 12
  • 56
  • 71

4 Answers4

7

Easy one, this. You are sending a non-transactional message to a transactional queue. MSMQ will discard the message.

Use the "MessageQueue.Send(Object, MessageQueueTransaction)" Method

If you enable Negative Source Journaling, you can look in the dead letter queue to see why messages gets discarded.

Cheers
John Breakwell

John Breakwell
  • 4,667
  • 20
  • 25
2

You need to create the queue before you can send to it (it's a one time operation, unless you delete the queue):

MessageQueue queue;
if (MessageQueue.Exists(path))
  queue = new MessageQueue(path);
else
  queue = MessageQueue.Create(path);
Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

if you have transactional queues, make sure to check that you are using transactions

using(MessageQueueTransaction tx = new MessageQueueTransaction()) {
    tx.Begin();
    queue.Send(message, tx);
    tx.Commit(); 
}

see more info in another post Message does not reach MSMQ when made transactional

Community
  • 1
  • 1
Ben Croughs
  • 2,566
  • 1
  • 20
  • 30
0

try swapping the order on your send.

I'd have to double check but i'm pretty sure the order is object, label

queue.Send(msg, "inputMessage");
Alan Barber
  • 983
  • 5
  • 15