コード例 #1
0
        public async Task can_route_multiple_message()
        {
            var key = Environment.TickCount;

            using (var router = new SubQueueRouter(testQueueFormatName, GetSubQueue))
            {
                await router.StartAsync();

                try
                {
                    using (var q = new QueueWriter(testQueueFormatName))
                    {
                        q.Write(new Message {
                            Label = "my.sq", AppSpecific = key
                        });
                        q.Write(new Message {
                            Label = "my.sq", AppSpecific = key + 1
                        });
                    }

                    using (var sq = new QueueReader(testQueueFormatName + ";sq"))
                    {
                        var got = sq.Read(Properties.AppSpecific, timeout: TimeSpan.FromMilliseconds(500));
                        Assert.AreEqual(key, got.AppSpecific);

                        got = sq.Read(Properties.AppSpecific, timeout: TimeSpan.FromMilliseconds(500));
                        Assert.AreEqual(key + 1, got.AppSpecific);
                    }
                }
                finally
                {
                    await router.StopAsync();
                }
            }
        }
コード例 #2
0
        public PriorityTransactionalRouter(string inputQueueFormatName)
        {
            Contract.Requires(inputQueueFormatName != null);
            if (Queues.IsTransactional(inputQueueFormatName) == QueueTransactional.None)
            {
                throw new ArgumentException(inputQueueFormatName + " is not a transactional queue");
            }

            InputQueueFormatName = inputQueueFormatName;
            _router = new SubQueueRouter(inputQueueFormatName, RouterByPriority);
        }
コード例 #3
0
        public async Task can_route_many()
        {
            using (var input = new QueueWriter(testQueueFormatName))
                using (var out1 = new QueueReader(testQueueFormatName + ";one"))
                    using (var out2 = new QueueReader(testQueueFormatName + ";two"))
                        using (var router = new SubQueueRouter(testQueueFormatName, GetSubQueue))
                        {
                            out1.Purge();
                            out2.Purge();

                            for (int i = 0; i < 1000; i++)
                            {
                                input.Write(new Message {
                                    Label = "1", AppSpecific = i
                                });
                                input.Write(new Message {
                                    Label = "2", AppSpecific = i
                                });
                            }
                            var sw = new Stopwatch();
                            sw.Start();

                            var rtask = router.StartAsync();
                            try
                            {
                                for (int i = 0; i < 1000; i++)
                                {
                                    var got = out1.Read(Properties.Label | Properties.AppSpecific);
                                    Assert.AreEqual("1", got.Label, "Label");
                                    Assert.AreEqual(i, got.AppSpecific, "AppSpecific");
                                    got = out2.Read(Properties.Label | Properties.AppSpecific);
                                    Assert.AreEqual("2", got.Label, "Label");
                                    Assert.AreEqual(i, got.AppSpecific, "AppSpecific");
                                }
                                sw.Stop();
                            }
                            finally
                            {
                                await router.StopAsync();
                            }

                            Console.WriteLine($"Reading 2000 routed messages took {sw.ElapsedMilliseconds:N0} MS");
                        }
        }