示例#1
0
        public void TestAsyncSubscriberStarvation()
        {
            Object waitCond = new Object();

            using (IConnection c = new ConnectionFactory().CreateConnection())
            {
                using (IAsyncSubscription helper = c.SubscribeAsync("helper"),
                                          start = c.SubscribeAsync("start"))
                {
                    helper.MessageHandler += (sender, arg) =>
                    {
                        System.Console.WriteLine("Helper");
                        c.Publish(arg.Message.Reply,
                            Encoding.UTF8.GetBytes("Hello"));
                    };
                    helper.Start();

                    start.MessageHandler += (sender, arg) =>
                    {
                        System.Console.WriteLine("Responsder");
		                string responseIB = c.NewInbox();
                        IAsyncSubscription ia = c.SubscribeAsync(responseIB);

                        ia.MessageHandler += (iSender, iArgs) =>
                        {
                            System.Console.WriteLine("Internal subscriber.");
                            lock (waitCond) { Monitor.Pulse(waitCond); }
                        };
                        ia.Start();
 
		                c.Publish("helper", responseIB,
                            Encoding.UTF8.GetBytes("Help me!"));
                    };

                    start.Start();
                     
                    c.Publish("start", Encoding.UTF8.GetBytes("Begin"));
                    c.Flush();

                    lock (waitCond) 
                    { 
                        Assert.IsTrue(Monitor.Wait(waitCond, 2000));
                    }
                }
            }
        }
示例#2
0
 public void TestInbox()
 {
     using (IConnection c = new ConnectionFactory().CreateConnection())
     {
         string inbox = c.NewInbox();
         Assert.IsFalse(string.IsNullOrWhiteSpace(inbox));
         Assert.IsTrue(inbox.StartsWith("_INBOX."));
     }
 }