Example #1
0
        public void Send(string data, MqQueueInfo mqInfo)
        {
            (string exchangeName, string routingKey, string queueName, bool durable, bool exclusive, bool autoDelete) = mqInfo;
            try
            {
                using IConnection connection = CreateFactory().CreateConnection();
                using var channel            = connection.CreateModel();

                channel.BasicPublish(exchangeName, routingKey, null, Encoding.UTF8.GetBytes(data));
            }
            catch (Exception ex)
            {
                throw new Exception("Возникла ошибка во время отправки сообщения в очередь.\n Message: " + ex.Message);
            }
        }
Example #2
0
        public void CreateRabbitQueue(MqQueueInfo mqInfo, bool exchangeExist)
        {
            try
            {
                (string exchangeName, string routingKey, string queueName, bool durable, bool exclusive, bool autoDelete) = mqInfo;

                using var conn    = CreateFactory().CreateConnection();
                using var channel = conn.CreateModel();
                if (!exchangeExist)
                {
                    channel.ExchangeDelete(exchangeName);
                    channel.ExchangeDeclare(exchangeName, ExchangeType.Direct);
                }
                DeclareQueue(channel, queueName, durable, exclusive, autoDelete);
                channel.QueueBind(queueName, exchangeName, routingKey, null);
            }
            catch (Exception ex)
            {
                throw new Exception("Возникла ошибка во время создания очереди.\n Message: " + ex.Message);
            }
        }