예제 #1
0
        protected void TestDeferredProcessing(string queueUriFormat, bool isTransactional)
        {
            const int deferredMessageCount = 10;
            const int millisecondsToDefer = 500;

            var configuration = GetInboxConfiguration(queueUriFormat, 1, isTransactional);

            var module = new DeferredMessageModule(deferredMessageCount);

            configuration.Modules.Add(module);

            using (var bus = new ServiceBus(configuration))
            {
                bus.Start();

                var ignoreTillDate = DateTime.Now.AddSeconds(5);

                for (var i = 0; i < deferredMessageCount; i++)
                {
                    EnqueueDeferredMessage(bus, ignoreTillDate);

                    ignoreTillDate = ignoreTillDate.AddMilliseconds(millisecondsToDefer);
                }

                // add the extra time else there is no time to process message being returned
                var timeout = ignoreTillDate.AddSeconds(150);
                var timedOut = false;

                _log.Information(string.Format("[start wait] : now = '{0}'", DateTime.Now));

                // wait for the message to be returned from the deferred queue
                while (!module.AllMessagesHandled()
                       &&
                       !timedOut)
                {
                    Thread.Sleep(millisecondsToDefer);

                    timedOut = timeout < DateTime.Now;
                }

                _log.Information(string.Format("[end wait] : now = '{0}' / timeout = '{1}' / timed out = '{2}'", DateTime.Now, timeout, timedOut));

                _log.Information(string.Format("{0} of {1} deferred messages returned to the inbox.",
                                               module.NumberOfDeferredMessagesReturned, deferredMessageCount));
                _log.Information(string.Format("{0} of {1} deferred messages handled.", module.NumberOfMessagesHandled,
                                               deferredMessageCount));

                Assert.IsTrue(module.AllMessagesHandled(), "All the deferred messages were not handled.");

                Assert.IsTrue(configuration.Inbox.ErrorQueue.IsEmpty());
                Assert.IsNull(configuration.Inbox.DeferredQueue.GetMessage());
                Assert.IsNull(configuration.Inbox.WorkQueue.GetMessage());
            }

            AttemptDropQueues(queueUriFormat);
        }
예제 #2
0
        private const int MillisecondsToDefer = 1000; // give the service bus enough time to start up

        #endregion Fields

        #region Methods

        protected void TestDeferredProcessing(string workQueueUriFormat, string deferredQueueUriFormat,
		                                      string errorQueueUriFormat, bool isTransactional)
        {
            var configuration = GetInboxConfiguration(workQueueUriFormat, deferredQueueUriFormat, errorQueueUriFormat, 1,
                                                      isTransactional);

            var module = new DeferredMessageModule();

            configuration.Modules.Add(module);

            using (var bus = new ServiceBus(configuration))
            {
                bus.Start();

                var message = bus.CreateTransportMessage(new SimpleCommand());

                message.IgnoreTillDate = DateTime.Now.AddMilliseconds(MillisecondsToDefer);
                message.RecipientInboxWorkQueueUri = configuration.Inbox.WorkQueue.Uri.ToString();

                configuration.Inbox.WorkQueue.Enqueue(message.MessageId, configuration.Serializer.Serialize(message));

                var timeout = DateTime.Now.AddMilliseconds(MillisecondsToDefer + 5000);

                // wait for the message to be returned from the deferred queue
                while ((!module.DeferredMessageReturned || !module.MessageHandled)
                       &&
                       timeout > DateTime.Now)
                {
                    Thread.Sleep(5);
                }

                Assert.IsTrue(module.DeferredMessageReturned, "Deferred message was never returned.");
                Assert.IsTrue(module.MessageHandled, "Deferred message was never handled.");

                Assert.IsTrue(configuration.Inbox.ErrorQueue.IsEmpty());
                Assert.IsNull(configuration.Inbox.DeferredQueue.GetMessage());
                Assert.IsNull(configuration.Inbox.WorkQueue.GetMessage());
            }

            AttemptDropQueues(workQueueUriFormat, errorQueueUriFormat);
        }