MSMQ 专用队列 - 未接收

发布于 2024-09-18 03:17:06 字数 1208 浏览 2 评论 0原文

MSMQ 新手...我的本地队列从未收到我的测试消息。我已验证消息队列和消息队列触发器正在我的“服务”对话框 (Vista Ultimate) 中运行。想法?

class ConsoleApplication
{
    private const string Path = @".\private$\SomeQueue";

    static void Main(string[] args)
    {
        var queue = !MessageQueue.Exists(Path) 
         ? MessageQueue.Create(Path) 
         : new MessageQueue(Path) { Formatter = new BinaryMessageFormatter() };

        queue.ReceiveCompleted += queue_ReceiveCompleted;
        queue.BeginReceive();
        queue.Send("test message");
        Console.ReadLine();
        queue.Close();
    }

    static void queue_ReceiveCompleted(object sender, 
                                        ReceiveCompletedEventArgs e)
    {
        Console.WriteLine("Received message...");
        var queue = (MessageQueue)sender;
        try
        {
            var message = queue.EndReceive(e.AsyncResult);
            Console.WriteLine("Processing message...");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            queue.BeginReceive();
        }
    }
}

编辑:只是有一个想法,尝试使用 MessageQueue.Delete(Path) 删除并重新创建队列。它奏效了。我想我的队列不知何故被挤掉了。

New to MSMQ... My local queue never receives my test message. I have verified that Message Queuing and Message Queuing Triggers are running in my Services dialog (Vista Ultimate). Thoughts?

class ConsoleApplication
{
    private const string Path = @".\private$\SomeQueue";

    static void Main(string[] args)
    {
        var queue = !MessageQueue.Exists(Path) 
         ? MessageQueue.Create(Path) 
         : new MessageQueue(Path) { Formatter = new BinaryMessageFormatter() };

        queue.ReceiveCompleted += queue_ReceiveCompleted;
        queue.BeginReceive();
        queue.Send("test message");
        Console.ReadLine();
        queue.Close();
    }

    static void queue_ReceiveCompleted(object sender, 
                                        ReceiveCompletedEventArgs e)
    {
        Console.WriteLine("Received message...");
        var queue = (MessageQueue)sender;
        try
        {
            var message = queue.EndReceive(e.AsyncResult);
            Console.WriteLine("Processing message...");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            queue.BeginReceive();
        }
    }
}

EDIT: Just had a thought, try deleting and re-creating the queue with MessageQueue.Delete(Path). And it worked. I guess my queue was hosed somehow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

带刺的爱情 2024-09-25 03:17:06

尝试添加

queue.ReceiveCompleted += queue_ReceiveCompleted;

static void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e) 事件的finally 块。

try adding

queue.ReceiveCompleted += queue_ReceiveCompleted;

in finally block of static void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e) event.

小霸王臭丫头 2024-09-25 03:17:06

我怀疑队列本身被破坏了。
更可能的是创建队列和访问队列之间的时间问题。
在专用队列可用之前,MSMQ 必须执行各种操作,例如在 LQS 目录中创建配置文件。

I doubt that the queue itself was broken.
More likely a timing issue between creating the queue and accessing it.
MSMQ has to perform various operations, such as create a config file in the LQS directory, before the private queue is available.

只是偏爱你 2024-09-25 03:17:06

您无法同时访问控制台。尝试执行 thread.Sleep() 并在回调中设置一个布尔值。然后,您可以在布尔值设置后执行 readline 来读取输出。

while (!received)
{
    System.Threading.Thread.Sleep(1000);
}
Console.ReadLine();

也许您可能想使用断点和 debug.WriteLine() 来读取写入 Visual Studio 输出窗口的输出。

You can't access the console concurrently. Try doing a thread.Sleep() and set a boolean in your callback. Then you can do a readline after the boolean is set to read your output.

while (!received)
{
    System.Threading.Thread.Sleep(1000);
}
Console.ReadLine();

Perhaps you might want to use a breakpoint and the debug.WriteLine() to read output written into the visual studio output window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文