示例#1
0
        public void ReceivesAndSendsMessage()
        {
            var configuration = new ConfigurationEntry {
                Alias = "#1", RedriveUrl = "http://here.com/", Active = true
            };
            var queueClientMock = new Mock <IQueueClient>(MockBehavior.Strict);

            queueClientMock.Setup(x => x.GetMessage()).Returns(new SqsMessage("id", "content")).Verifiable();
            var messageProcessorMock = new Mock <IMessageProcessor>(MockBehavior.Strict);

            messageProcessorMock.Setup(x => x.ProcessMessage(It.IsAny <string>(), It.IsAny <ConfigurationEntry>())).Verifiable();
            queueClientMock.Setup(x => x.DeleteMessage(It.IsAny <IMessage>())).Callback(() => Thread.Sleep(2000));
            var processorFactoryMock = new Mock <IMessageProcessorFactory>(MockBehavior.Strict);

            processorFactoryMock.Setup(x => x.CreateMessageProcessor(It.IsAny <ConfigurationEntry>())).Returns(messageProcessorMock.Object).Verifiable();

            var processor = new QueueProcessor();

            processor.Init(queueClientMock.Object, processorFactoryMock.Object, configuration);
            processor.Start();
            Thread.Sleep(1000);
            processor.Stop();

            queueClientMock.Verify(x => x.GetMessage(), Times.Exactly(1));
            messageProcessorMock.Verify(x => x.ProcessMessage(It.IsAny <string>(), It.IsAny <ConfigurationEntry>()), Times.Exactly(1));
            queueClientMock.Verify(x => x.DeleteMessage(It.IsAny <IMessage>()), Times.Exactly(1));
            processorFactoryMock.Verify(x => x.CreateMessageProcessor(It.IsAny <ConfigurationEntry>()), Times.Exactly(1));
        }
        public static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            var rabbitSettings = configuration.GetSection("rabbitmq-settings");

            var config = new QueueConfig
            {
                HostName  = rabbitSettings["hostName"],
                UserName  = rabbitSettings["userName"],
                Password  = rabbitSettings["password"],
                QueueName = rabbitSettings["sendQueue"]
            };

            DisplayRabbitSettings(config);
            Console.WriteLine("Starting Employee Service Queue Processor....");
            Console.WriteLine();


            var processor = new QueueProcessor(config);

            processor.Start();
        }
        protected override void OnStart(string[] args)
        {
            var servicesSetup = new ServicesSetup();

            servicesSetup.Setup();

            var serviceProvider = servicesSetup.GetServiceProvider();

            _queueProcessor = serviceProvider.GetService <QueueProcessor>();

            _queueProcessor.Start();
        }
示例#4
0
        public static void Main(string [] args)
        {
            var logger = LogManager.GetCurrentClassLogger();

            logger.Info("FACEPHONE.PROCESSOR================================");
            var driver    = CreateDriver();
            var humanizer = new Humanizer.Humanizer(driver);
            var processor = new QueueProcessor(driver, humanizer);

            logger.Info("Starting...");
            processor.Start();
            processor.ProcessorTask.Wait();
            logger.Info("Stopping...");
        }
示例#5
0
        public void StartStopTest()
        {
            var queueReceiverAdapter = Substitute.For <IQueueReceiveAdapter>();

            var queueProcessor = new QueueProcessor(queueReceiverAdapter, null);

            queueProcessor.Start();

            queueReceiverAdapter.ReceivedWithAnyArgs().Start(null);
            queueReceiverAdapter.DidNotReceive().Stop();

            queueProcessor.Stop();

            queueReceiverAdapter.Received().Stop();
        }
示例#6
0
        public void DoesNothingWithoutQueuedMessage()
        {
            var configuration = new ConfigurationEntry {
                Alias = "#1", RedriveUrl = "http://here.com/", Active = true
            };
            var queueClientMock = new Mock <IQueueClient>(MockBehavior.Strict);

            queueClientMock.Setup(x => x.GetMessage()).Callback(() => Thread.Sleep(2000)).Returns((SqsMessage)null).Verifiable();

            var processor = new QueueProcessor();

            processor.Init(queueClientMock.Object, null, configuration);
            processor.Start();
            Thread.Sleep(1000);
            processor.Stop();

            queueClientMock.Verify(x => x.GetMessage(), Times.Exactly(1));
        }
示例#7
0
        public void ProcessElementTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            var queueSendAdapter = environmentFactory.QueueEnvironment.QueueSendAdapter;

            queueSendAdapter.Clear();

            var queueReceiverAdapter       = environmentFactory.QueueEnvironment.QueueReceiveAdapter;
            var directTelemetryDataService = Substitute.For <IDirectTelemetryDataService>();

            int COUNT = 50;

            var outputList = new List <TelemetryData>(COUNT);

            directTelemetryDataService.When(d => d.RecordTelemetryData(Arg.Any <TelemetryData>())).Do(call => outputList.Add((TelemetryData)call.Args()[0]));

            var queueProcessor = new QueueProcessor(queueReceiverAdapter, directTelemetryDataService);

            queueProcessor.Start();

            var inputList = new List <TelemetryData>(COUNT);

            for (var i = 0; i < COUNT; i++)
            {
                var inputTd = new TelemetryData((i % 5).ToString(), $"{{\"p\": {i}}}", DateTime.UtcNow);
                inputList.Add(inputTd);
                queueSendAdapter.Send(inputTd);
            }

            var ok = false;

            for (var r = 0; r < 30; r++)
            {
                if (outputList.Count == COUNT)
                {
                    bool isOk = true;
                    for (var i = 0; i < COUNT; i++)
                    {
                        var input  = inputList[i];
                        var output = outputList[i];

                        if (input.DeviceId != output.DeviceId.Trim() || input.Payload != output.Payload)
                        {
                            isOk = false;
                            break;
                        }
                    }
                    if (isOk)
                    {
                        ok = true;
                        break;
                    }
                }
                Thread.Sleep(100);
            }

            queueProcessor.Stop();

            Assert.IsTrue(ok);
        }