Beispiel #1
0
        public async Task can_remove_subscription()
        {
            using (var requestWriter = new QueueWriter(requestFN))
                using (var replyReader = new QueueReader(replyFN))
                {
                    var addReq = new Message {
                        AppSpecific = (int)PubSubAction.Add, ResponseQueue = replyFN
                    };
                    addReq.BodyUTF8("thing.one" + Environment.NewLine + "thing.two");
                    requestWriter.Write(addReq);

                    var removeReq = new Message {
                        AppSpecific = (int)PubSubAction.Remove, ResponseQueue = replyFN
                    };
                    removeReq.BodyUTF8("thing.one");
                    requestWriter.Write(removeReq);

                    var listReq = new Message {
                        AppSpecific = (int)PubSubAction.List, ResponseQueue = replyFN
                    };
                    requestWriter.Write(listReq);

                    var got = replyReader.Read(timeout: TimeSpan.FromSeconds(3));
                    Assert.IsNotNull(got);
                    Assert.AreEqual("thing.two", got.BodyUTF8());
                }
        }
        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();
                }
            }
        }
        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");
                        }
        }
 private void Server(int count)
 {
     using (var requestQ = new QueueReader(requestQueueFormatName))
         using (var replyQ = new QueueWriter(replyQueueFormatName))
         {
             for (int i = 0; i < count; i++)
             {
                 var msg = requestQ.Read(Properties.All, TimeSpan.FromSeconds(0.5));
                 msg.CorrelationId = msg.Id;
                 replyQ.Write(msg);
             }
         }
 }
Beispiel #5
0
        public async Task can_route_non_transactional()
        {
            using (var router = new NonTransactionalRouter(inputQueueFormatName, sender, msg => msg.Label.Contains("1") ? outSend1 : outSend2))
            {
                await sender.StartAsync();

                try
                {
                    var rtask = router.StartAsync();
                    input.Write(new Message {
                        Label = "1", AppSpecific = 1
                    });
                    var got = outRead1.Read();
                    Assert.AreEqual("1", got.Label);
                }
                finally
                {
                    await router?.StopAsync();

                    await sender.StopAsync();
                }
            }
        }
Beispiel #6
0
        public async Task can_route_transactional()
        {
            using (var router = new TransactionalRouter(inputQueueFormatName, sender, Route))
            {
                await sender.StartAsync();

                try
                {
                    var rtask = router.StartAsync();
                    input.Write(new Message {
                        Label = "1", AppSpecific = 1
                    }, QueueTransaction.Single);
                    var got = outRead1.Read();
                    Assert.AreEqual("1", got.Label);
                }
                finally
                {
                    await router?.StopAsync();

                    await sender.StopAsync();
                }
            }
        }
        private async Task PerformWrites(string queueName, int numWrites)
        {
            ParmCheck.NotNullOrEmpty(nameof(queueName), queueName);
            ParmCheck.Positive(nameof(numWrites), numWrites);

            var queueWriter = new QueueWriter(_connectionString, queueName);

            for (int i = 0; i < numWrites; i++)
            {
                FishObservation observation = DataGenerator.CreateFishObservation();

                string messageId = await queueWriter.Write(observation);

                Console.WriteLine($"Message {messageId} sent.");
            }
        }
Beispiel #8
0
        /// <summary>
        /// Posts a <paramref name="message"/> to the <paramref name="queue"/> with acknowledgement requested to be sent to <see cref="AdminQueueFormatName"/>.
        /// </summary>
        public Tracking RequestDelivery(Message message, QueueWriter queue, QueueTransaction transaction = null)
        {
            Contract.Requires(message != null);
            Contract.Requires(queue != null);
            Contract.Assert(_run != null);
            Contract.Assert(_adminQueue != null);

            message.AcknowledgmentTypes |= AcknowledgmentTypes.FullReachQueue;
            message.TimeToReachQueue     = ReachQueueTimeout;
            message.AdministrationQueue  = _adminQueue.FormatName;
            queue.Write(message, transaction);

            // acknowledgements for multicast messages get an empty DestinationQueue, so we need to remove it here
            var formatName = queue.FormatName.StartsWith("multicast=", StringComparison.OrdinalIgnoreCase)? "" : queue.FormatName;

            return(new Tracking(formatName, message.Id, message.LookupId));
        }
Beispiel #9
0
        public void can_peek_when_opened_with_move_acces()
        {
            var fn   = Queues.TryCreate(".\\private$\\subqtest", QueueTransactional.None);
            var sqfn = fn + ";sq";

            using (var qWriter = new QueueWriter(fn))
            {
                qWriter.Write(new Message {
                    AppSpecific = 234
                });
            }
            using (var qReader = new QueueReader(fn))
                using (var subQueue = new SubQueue(sqfn))
                {
                    var msg = qReader.Peek(Properties.LookupId);
                    Queues.MoveMessage(qReader, subQueue, msg.LookupId);
                    var got = subQueue.Read();
                    Assert.AreEqual(234, got.AppSpecific);
                }
        }