Example #1
0
        /// <summary>
        /// Cria um canal de conexão com uma fila asincrona
        /// </summary>
        public Channel <TRequest> CreateChannel <TRequest>(string?queueName = null)
        {
            if (IsClosed)
            {
                throw new InvalidOperationException("No RabbitMQ connections are available to perform this action");
            }

            var model = _rabbitConnection.CreateModel();

            model.BasicQos(0, _configuration.PrefetchCount, false);
            var atrr    = _configuration.GetMaping <TRequest>();
            var channel = new Channel <TRequest>(_services, model, _serializer, _configuration, atrr, queueName);
            var args    = new Dictionary <string, object>();

            if (_configuration.MessagesMaxLength.HasValue)
            {
                args.Add("x-max-length", _configuration.MessagesMaxLength.Value);
            }
            if (_configuration.MessagesBytesMaxLength.HasValue)
            {
                args.Add("max-length-bytes", _configuration.MessagesBytesMaxLength.Value);
            }
            if (_configuration.Ttl.HasValue)
            {
                args.Add("x-message-ttl", (int)_configuration.Ttl.Value.TotalMilliseconds);
            }
            model.QueueDeclare(channel.Descriptor.QueueName, true, false, false, args);
            model.QueueDeclare(channel.Descriptor.DeadLetterQueueName, true, false, true, new Dictionary <string, object>());
            return(channel);
        }