Ejemplo n.º 1
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogger logProvider,
                                                 int timeOut,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updateTime,
                                                 bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var trace = SharedSetup.CreateTrace("consumer-poison"))
            {
                using (var metrics = new Metrics.Metrics(queueConnection.Queue))
                {
                    var addInterceptorConsumer = InterceptorAdding.No;
                    if (addInterceptors)
                    {
                        addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                    }

                    using (
                        var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider,
                                                                                 metrics,
                                                                                 true, enableChaos, scope, trace.Source))
                    {
                        using (
                            var queue =
                                creator.CreateMethodConsumer(queueConnection, x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
                        {
                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, null);

                            var waitForFinish = new ManualResetEventSlim(false);
                            waitForFinish.Reset();
                            queue.Start();
                            for (var i = 0; i < timeOut; i++)
                            {
                                if (VerifyMetrics.GetPoisonMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                                {
                                    break;
                                }

                                Thread.Sleep(1000);
                            }
                        }

                        VerifyMetrics.VerifyPoisonMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                               messageCount);
                    }
                }
            }
        }
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogger logProvider,
                                                 int timeOut,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updateTime,
                                                 string route,
                                                 bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var metrics = new Metrics.Metrics(queueConnection.Queue))
            {
                var addInterceptorConsumer = InterceptorAdding.No;
                if (addInterceptors)
                {
                    addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                }

                using (
                    var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics,
                                                                             true, enableChaos, scope))
                {
                    using (
                        var queue =
                            creator.CreateConsumer(queueConnection))
                    {
                        SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                              heartBeatMonitorTime, updateTime, route);

                        var waitForFinish = new ManualResetEventSlim(false);
                        waitForFinish.Reset();

                        //start looking for work
                        queue.Start <TMessage>((message, notifications) =>
                        {
                            MessageHandlingShared.HandleFakeMessageNoOp();
                        });

                        for (var i = 0; i < timeOut; i++)
                        {
                            if (VerifyMetrics.GetPoisonMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                    }
                    VerifyMetrics.VerifyPoisonMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(), messageCount);
                }
            }
        }
Ejemplo n.º 3
0
        public void RunConsumer <TTransportInit>(string queueName,
                                                 string connectionString,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogProvider logProvider,
                                                 int timeOut,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updateTime)
            where TTransportInit : ITransportInit, new()
        {
            using (var metrics = new Metrics.Metrics(queueName))
            {
                var addInterceptorConsumer = InterceptorAdding.No;
                if (addInterceptors)
                {
                    addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                }

                using (
                    var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics,
                                                                             true))
                {
                    using (
                        var queue =
                            creator.CreateMethodConsumer(queueName,
                                                         connectionString))
                    {
                        SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                              heartBeatMonitorTime, updateTime, null);

                        var waitForFinish = new ManualResetEventSlim(false);
                        waitForFinish.Reset();
                        queue.Start();
                        for (var i = 0; i < timeOut; i++)
                        {
                            if (VerifyMetrics.GetPoisonMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                    }
                    VerifyMetrics.VerifyPoisonMessageCount(queueName, metrics.GetCurrentMetrics(), messageCount);
                }
            }
        }
Ejemplo n.º 4
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogger logProvider,
                                                 int timeOut,
                                                 int readerCount,
                                                 int queueSize,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updateTime,
                                                 string route,
                                                 bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var metrics = new Metrics.Metrics(queueConnection.Queue))
            {
                var addInterceptorConsumer = InterceptorAdding.No;
                if (addInterceptors)
                {
                    addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                }

                using (
                    var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics,
                                                                             true, enableChaos, scope))
                {
                    using (var schedulerCreator = new SchedulerContainer())
                    {
                        using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                        {
                            taskScheduler.Configuration.MaximumThreads = workerCount;
                            taskScheduler.Configuration.MaxQueueSize   = queueSize;

                            taskScheduler.Start();
                            var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                            using (
                                var queue =
                                    creator
                                    .CreateConsumerQueueScheduler(
                                        queueConnection, taskFactory))
                            {
                                SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount, heartBeatTime,
                                                                      heartBeatMonitorTime, updateTime, route);

                                //start looking for work
                                queue.Start <TMessage>((message, notifications) =>
                                {
                                    MessageHandlingShared.HandleFakeMessageNoOp();
                                });

                                for (var i = 0; i < timeOut; i++)
                                {
                                    if (VerifyMetrics.GetPoisonMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                                    {
                                        break;
                                    }
                                    Thread.Sleep(1000);
                                }

                                //wait for last error to be saved if needed.
                                Thread.Sleep(3000);
                            }
                        }
                        VerifyMetrics.VerifyPoisonMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(), messageCount);
                    }
                }
            }
        }
        public void RunConsumer <TTransportInit>(string queueName,
                                                 string connectionString,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogProvider logProvider,
                                                 int timeOut,
                                                 int readerCount,
                                                 int queueSize,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updatetime)
            where TTransportInit : ITransportInit, new()
        {
            using (var metrics = new Metrics.Metrics(queueName))
            {
                var addInterceptorConsumer = InterceptorAdding.No;
                if (addInterceptors)
                {
                    addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                }

                using (
                    var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics,
                                                                             true))
                {
                    using (var schedulerCreator = new SchedulerContainer())
                    {
                        using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                        {
                            taskScheduler.Configuration.MaximumThreads = workerCount;
                            taskScheduler.Configuration.MaxQueueSize   = queueSize;

                            taskScheduler.Start();
                            var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                            using (
                                var queue =
                                    creator
                                    .CreateConsumerMethodQueueScheduler(
                                        queueName, connectionString, taskFactory))
                            {
                                SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount, heartBeatTime,
                                                                      heartBeatMonitorTime, updatetime, null);
                                queue.Start();
                                for (var i = 0; i < timeOut; i++)
                                {
                                    if (VerifyMetrics.GetPoisonMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                                    {
                                        break;
                                    }
                                    Thread.Sleep(1000);
                                }

                                //wait for last error to be saved if needed.
                                Thread.Sleep(3000);
                            }
                        }
                        VerifyMetrics.VerifyPoisonMessageCount(queueName, metrics.GetCurrentMetrics(), messageCount);
                    }
                }
            }
        }