简体   繁体   English

在专用队列中未收到MSMQ消息

[英]MSMQ messages not being received in private queue

I am new to programming and having issues with it . 我是编程新手,并且对此有疑问。 I don't know why messages are not appearing in the private queue... 我不知道为什么消息没有出现在私人队列中...

this is the code that i was working on but quiet not working although i have created another msmq application without async which is working but here problem arises. 这是我正在处理的代码,但是安静地无法正常工作,尽管我创建了另一个没有异步功能的msmq应用程序,但是这里出现了问题。

class Program
{
   static MessageQueue queue = new MessageQueue();

    static void Main(string[] args)
    {



        queue.Path = @".\Private$\NPQueue-Fall17-3"; 
         queue.Formatter=new XmlMessageFormatter();
        if (MessageQueue.Exists(queue.Path)==false)
            MessageQueue.Create(queue.Path);
        MessageQueueTransaction trans = new MessageQueueTransaction();
        try {
            trans.Begin();   
            queue.Send("hi1");
            queue.Send("hi2");
            throw new Exception("error");
            queue.Send("hi3");
            queue.Send("hi4");
           trans.Commit();

            Console.WriteLine(queue.Receive().Body);
            Console.WriteLine(queue.Receive().Body);
            Console.WriteLine(queue.Receive().Body);
            Console.WriteLine(queue.Receive().Body);
            Console.Read();


        }
        catch
        {
           trans.Abort();
        }
        queue.ReceiveCompleted += queue_ReceieveCompleted;
        queue.BeginReceive();
        Console.Read();
        trans.Commit();

    }

    private static void queue_ReceieveCompleted(object sender, ReceiveCompletedEventArgs e)
    {
        var msg = queue.EndReceive(e.AsyncResult);
        Console.WriteLine(msg.Body);
        queue.BeginReceive();  //bar bar read kelye lagaya hai
    }
}

} }

You have hardcoded a throw expection into the transaction. 您已将抛出期望硬编码到事务中。 Which will cause, an exception, which will run an abort. 这将导致异常,并导致异常终止。 With the transaction aborted, you literally aren't sending anything. 随着事务中止,您实际上没有发送任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM