Where did my Message Queue sent messages go?
I have an application that uses MSMQ that is working very well when both the producer and consumer are on the same machine.
Yesterday, for the first time, I tried to create another producer that would run on a separate machine. The queue is a private queue, and before, both sides referenced it as
string strQueueName = ".\Private$\MyQueue";
I tried several ways to reference this queue from the remote machine. My server name is "groucho", so I tried
string strQueueName = "groucho\Pr开发者_如何学运维ivate$\MyQueue";
but this consistently threw an "invalid queue path name" exception.
A fellow developer suggested I try the following, which avoids the exception:
string strQueueName = "FORMATNAME:DIRECT =OS:grouch\\private$\\SDVQueue";
This no longer throws the exception, but it does not seem to work, either, as I do not see the messages in the queue.
The server is Windows Server 2008 R2. The queue is set up (I just noticed) so that "Everyone" can Receive and Peek, but not Send, but when I try to add "Send", I get an error dialog that says "The security descriptor cannot be set, Error: Access is denied". I do have Admin privileges on this box.
I know from reading other posts that there is all kinds of security that comes into play, but I do not see any errors in the event logs on either the sender or the host machine.
If this is a security issue, how can I see what the issue is?
Thanks!
Here is the complete test code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Messaging;
namespace RemoteQueue
{
class Program
{
static void Main(string[] args)
{
string name = "FORMATNAME:DIRECT =OS:groucho\\private$\\SDVQueue";;
string input = null;
MessageQueue queue = null;
try
{
queue = new MessageQueue(name);
string key = "key";
for (int i = 0; i < 200; i++)
{
Message msgToSend = new Message();
string value = "value_" + i;
msgToSend.Body = string.Format("{0},{1}", key, value);
Console.WriteLine("Sending message " + i);
queue.Send(msgToSend, "otherpart");
}
}
catch (MessageQueueException me)
{
Console.WriteLine("ERROR: caught message queue exception: " + me.Message);
}
Console.WriteLine("Type any key to exit...");
input = Console.ReadLine();
}
}
}
If you send a message from one server and then look in your outbound queues, you should see a temporary queue which has been created with the intention of transmitting your message. You should be able to see your message on the queue.
Now go onto the receiving server.
In order to set permissions on the queue you need to take ownership of it. In the queue properties -> Security tab -> Advanced -> Owner tab -> Change Owner to. You should see your windows principal in the list.
This will enable you to set the send permissions. Once this has been done check the outbound queues on the sending server and the message should now have been transmitted.
Hope this helps.
Add the following to your example. It should show up in the dead letter queue, if its not getting processed by the server.
...
queue = new MessageQueue(name);
queue.DefaultPropertiesToSend = new DefaultPropertiesToSend();
queue.DefaultPropertiesToSend.UseDeadLetterQueue = true;
....
Could be a security issue on your msmq server.
Try setting the 'everyone full control' on the queue
精彩评论