public void SendOrder(string queueName, QueueItemOrder queueItemOrder)
        {
            try
            {
                var builder = new ConfigurationBuilder()
                              .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
                IConfigurationRoot config = builder.Build();
                var _hostname             = config.GetSection("RabbitMQ").GetSection("HostName").Value;
                var _username             = config.GetSection("RabbitMQ").GetSection("UserName").Value;
                var _password             = config.GetSection("RabbitMQ").GetSection("Password").Value;
                var _queuePreFix          = config.GetSection("RabbitMQ").GetSection("QueuePreFix").Value;

                var factory = new ConnectionFactory
                {
                    HostName = _hostname,
                    UserName = _username,
                    Password = _password
                };
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        QueueProducer.Publish(channel, queueName + _queuePreFix, queueItemOrder);
                    }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public static void Publish(IModel channel, string _queueName, QueueItemOrder queueItemOrder)
        {
            channel.QueueDeclare(_queueName,
                                 durable: false,
                                 exclusive: false,
                                 autoDelete: false,
                                 arguments: null);



            var body = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(queueItemOrder)
                );

            channel.BasicPublish(exchange: "",
                                 routingKey: _queueName,
                                 basicProperties: null,
                                 body: body);
        }
Пример #3
0
 public void DirectToArea(string area, QueueItemOrder queueItemOrder)
 {
     _RabbitRepository.SendOrder(area, queueItemOrder);
 }