Пример #1
0
        public async Task <bool> PushMessageToQ(MQItem mQItem)
        {
            try
            {
                //TODO: move hostname to localhost
                var factory = new ConnectionFactory()
                {
                    HostName = configuration.GetValue <string>("RabbitMQ:HostName")
                };
                using (var connection = factory.CreateConnection())
                {
                    using (var channel = connection.CreateModel())
                    {
                        channel.QueueDeclare(queue: "counter",
                                             durable: true,
                                             exclusive: false,
                                             autoDelete: false,
                                             arguments: null);

                        await cacheAccessor.SetRequestToCache(mQItem);

                        channel.BasicPublish(exchange: "counter", routingKey: "counter", body: Helpers.ObjectToBytes(mQItem), basicProperties: null);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} | {ex.StackTrace}");
                return(false);
            }
        }