Не может определить, существует ли очередь с указанным именем формата

Я получаю исключение при выполнении следующего кода. Какие-либо идеи что не так?

string queueName = "FormatName:Direct=TCP:1.1.1.1\\Private$\\test";
MessageQueue queue;

if (MessageQueue.Exists(queueName))
     queue = new System.Messaging.MessageQueue(queueName);
else queue = MessageQueue.Create(queueName);

queue.Send(sWriter.ToString());

Править: Вот сообщение об исключении и первая строка stacktrace

Не может определить, существует ли очередь с указанным именем формата.
в System. Обмен сообщениями. MessageQueue. Существует (Строковый путь)

Это работает на локальную очередь между прочим.

16
задан AustinWBryan 14 October 2018 в 19:18
поделиться

1 ответ

From your sample, it looks like you're trying to check whether a remote private queue exists, but as the MessageQueue.Exists documentation says:

Exists cannot be called to verify the existence of a remote private queue.

Trying to do so will produce an InvalidOperationException.


If you really need this information for your workflow, you can use the MessageQueue. GetPrivateQueuesByMachine method and iterate the results to find a match. If you do, I recommend reading Are Remote MSMQ Queues Reliable?, which discusses this approach in some depth.

This post from the excellent "MSMQ from the plumber's mate" blog suggests another alternative: don't even check whether your queues exist, "but instead handle the non-delivery of the message should it turn out that the queue doesn't exist." (You'll need to track administration queues and/or dead-letter queues, but you should probably be doing that anyway.)

39
ответ дан 30 November 2019 в 15:47
поделиться
Другие вопросы по тегам:

Похожие вопросы: