private static async Task _GenerateMessages(IConfiguration configuration)
        {
            var queueChannel = await _InitializeWorkQueueChannel(configuration);

            var queuePublisher = new QueuePublisher(queueChannel);

            var iterationDelay          = configuration.GetValue("IterationDelay", TimeSpan.FromSeconds(30));
            var batchSize               = configuration.GetValue("BatchSize", 96);
            var remainingMessagesToSend = configuration.GetValue("RemainingMessagesToSend", 500);

            while (remainingMessagesToSend > 0)
            {
                for (int i = 0; i < batchSize && remainingMessagesToSend > 0; remainingMessagesToSend--, i++)
                {
                    _SendMessage(queuePublisher);
                }

                Log.Debug("Sent message batch");

                if (remainingMessagesToSend > 0)
                {
                    await Task.Delay(iterationDelay);
                }
            }

            queueChannel.Dispose();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.CursorVisible   = false;
            Console.ForegroundColor = ConsoleColor.White;

            using (var terminationQueueConsumer = new QueueConsumer(AppSettings.Instance.AppConfig.RabbitMQ.KitchenTerminationQueueName))
                using (var eventPublisher = new QueuePublisher(AppSettings.Instance.AppConfig.RabbitMQ.EventQueueName))
                {
                    var kitchenShelvesManager = new KitchenShelvesManager(
                        new CourierTimerFactory(),
                        new OrderDeterriorationTimerFactory(),
                        new QueueNotificationService(eventPublisher),
                        new ShelvesInitializationFromConfigFile());

                    terminationQueueConsumer.Received += (sender, ea) =>
                    {
                        var terminationProcess = new KitchenTerminationProcess(kitchenShelvesManager);
                    };

                    IRenderer renderer = new KitchenConsoleRenderer(kitchenShelvesManager);

                    using (var renderEngine = new SimpleTimerRenderEngine(renderer, fps: 1))
                    {
                        renderEngine.Start();

                        using (var kitchenOrdersConsumer = new KitchenQueueConsumer(
                                   new QueueConsumer(AppSettings.Instance.AppConfig.RabbitMQ.KitchenQueueName),
                                   kitchenShelvesManager))
                        {
                            Console.ReadKey();
                        }
                    }
                }
        }
Пример #3
0
        private static void EmitOrdersService_OnOutOfOrders(object sender, EventArgs args)
        {
            using (var queuePublisher = new QueuePublisher(AppSettings.Instance
                                                           .AppConfig.RabbitMQ.KitchenTerminationQueueName))
            {
                queuePublisher.Publish(new object());
            }

            Environment.Exit(0);
        }
Пример #4
0
        private static async Task SendRequest()
        {
            var         semaphoreSlim = new SemaphoreSlim(0, 1);
            IBusControl bus           = null;

            await Task.Factory.StartNew(async() =>
            {
                var queueGuid           = Guid.NewGuid().ToString();
                var models              = new List <CorrelationResponseModel>();
                var correlationConsumer = new CorrelationConsumer(model =>
                {
                    Console.WriteLine($"added model with index: {model.ResponseIndex}");
                    models.Add(model);

                    if (models.Count == model.TotalCount)
                    {
                        Console.WriteLine("Got all models in list");
                        semaphoreSlim.Release();
                    }
                });

                bus = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
                {
                    AzureServiceBusFactory.ConfigureHost(cfg);

                    cfg.ReceiveEndpoint(queueGuid, configurator =>
                    {
                        configurator.Consumer(() => correlationConsumer);
                    });
                });

                await bus.StartAsync();

                await QueuePublisher.StartCorrelation(queueGuid);

                // Do not stop bus here, otherwise the consumer does not receive notifications
                // await bus.StopAsync();
            }).ConfigureAwait(false);


            await semaphoreSlim.WaitAsync();

            await bus?.StopAsync();

            /*
             * var result = await RpcPublisher.SendToCoreRpcQueue(new StringIntRequestModel
             * {
             *  IntValue = _intValue++, StringValue = "FrameworkRpcCall"
             * });
             *
             * Console.WriteLine(
             *  $"{Environment.NewLine}string: {result.StringValue}, int: {result.IntValue}, date: {result.DateTime}{Environment.NewLine}");
             */
        }
        public EventingQueuePrioritizer(QueueChannel consumerChannel, QueueChannel publisherChannel)
        {
            ConsumerChannel = consumerChannel;

            var queuePublisher = new QueuePublisher(publisherChannel);

            QueuePublisher = queuePublisher;

            var consumer = new AsyncEventingBasicConsumer(consumerChannel.Model);

            consumer.Received += _OnMessageReceived;
            consumerChannel.Model.BasicConsume(queue: consumerChannel.QueueName,
                                               autoAck: false,
                                               consumer: consumer);
        }
Пример #6
0
        static void Main(string[] args)
        {
            var jsonFileOrderProvider = new JsonFileOrderProvider("orders.json");

            using (var queuePublisher = new QueuePublisher(AppSettings.Instance.AppConfig.RabbitMQ.KitchenQueueName))
            {
                queuePublisher.Published += (sender, ea) =>
                {
                    Console.WriteLine($" [x] Sent order {ea.Message}");
                };

                var emitOrdersService = new EmitOrdersService(queuePublisher, jsonFileOrderProvider);

                emitOrdersService.OnOutOfOrders += EmitOrdersService_OnOutOfOrders;
                emitOrdersService.StartEmittingOrders();
                Console.ReadKey();
            }
        }
        private static void _SendMessage(QueuePublisher queuePublisher)
        {
            var message = new Message
            {
                Header = new Header
                {
                    Timestamp = Timestamp.FromDateTime(DateTime.UtcNow),
                },
                Payload = new Payload
                {
                    Body = Guid.NewGuid().ToString(),
                }
            };

            queuePublisher.EnqueueJsonMessage(message);
            message.Payload.Body = Guid.NewGuid().ToString();

            queuePublisher.EnqueueBinaryMessage(message);
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Hello World!");
                });
            });

            Task.Factory.StartNew(async() =>
            {
                try
                {
                    await QueuePublisher.SendToCoreQueue(new StringIntRequestModel
                    {
                        IntValue    = 13,
                        StringValue = "FrameworkCall"
                    });

                    var response = await RpcPublisher.SendToCoreRpcQueue(new StringIntRequestModel
                    {
                        IntValue    = 13,
                        StringValue = "FromFrameworkRpcCall"
                    });

                    Console.WriteLine(
                        $"int: {response.IntValue}, string: {response.StringValue}, time: {response.DateTime}");
                }
                catch (Exception e)
                {
                }
            });
        }
        public KitchenTerminationProcess(KitchenShelvesManager kitchenShelves)
        {
            var timer = new Timer();

            timer.Interval  = TimeSpan.FromSeconds(1).TotalMilliseconds;
            timer.AutoReset = true;

            timer.Elapsed += (sender, args) =>
            {
                // wait for kitchen to stop working
                if (kitchenShelves.All(x => x.Orders.Count == 0))
                {
                    using (var eventTerminationQueuePublisher = new QueuePublisher(AppSettings.Instance.AppConfig.RabbitMQ.EventLogDisplayTerminationQeueueName))
                    {
                        eventTerminationQueuePublisher.Publish(new object());
                    }

                    Environment.Exit(0);
                }
            };

            timer.Start();
        }
 public EmployeeController(QueuePublisher queuePublisher)
 {
     this.queuePublisher = queuePublisher;
 }
Пример #11
0
        public void Notify(string exchange, string publishingGroup, string eventToPost, object objectToPublish)
        {
            var pubs = QueuePublisher.CreateEvent(exchange, publishingGroup, eventToPost, objectToPublish);

            pubs.PublishEvent();
        }
Пример #12
0
 public QueueNotificationService(QueuePublisher queuePublisher)
 {
     this.queuePublisher = queuePublisher;
 }
Пример #13
0
 /// <summary>
 /// Create new instance of <see cref="EmitOrdersService"/>
 /// </summary>
 /// <param name="publisher">RabbitMQ single queue publisher</param>
 public EmitOrdersService(QueuePublisher publisher, IOrderProvider orderProvider)
 {
     this.publisher     = publisher;
     this.orderProvider = orderProvider;
 }
 public async Task Consume(ConsumeContext <CorrelationStartRequest> context)
 {
     await QueuePublisher.RespondToCorrelation(context.Message.QueueName);
 }