Exemple #1
0
        internal static async Task QoS(this RabbitMQSession session, RabbitMQChannel channel, QoSInfo qos)
        {
            var data = session.GetChannelData(channel.ChannelId);

            data.CommonTcs = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously);
            await session.Writer.SendBasicQoSAsync(channel.ChannelId, ref qos).ConfigureAwait(false);

            await data.CommonTcs.Task.ConfigureAwait(false);
        }
        public static async ValueTask QueueDeclareNoWaitAsync(this RabbitMQSession session, RabbitMQChannel channel, QueueDeclare queue)
        {
            session.Channels.TryGetValue(channel.ChannelId, out var src);
            var data = session.GetChannelData(channel.ChannelId);

            queue.NoWait = true;
            await session.Writer.SendQueueDeclareAsync(channel.ChannelId, queue).ConfigureAwait(false);

            data.Queues.Add(queue.Name, queue);
        }
        public static async ValueTask QueuePurgeNoWaitAsync(this RabbitMQSession session, RabbitMQChannel channel, QueuePurge queue)
        {
            session.Channels.TryGetValue(channel.ChannelId, out var src);
            var data = session.GetChannelData(channel.ChannelId);

            src.CommonTcs = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously);
            queue.NoWait  = true;
            await session.Writer.SendQueuePurgeAsync(channel.ChannelId, queue).ConfigureAwait(false);

            data.Queues.Remove(queue.Name);
        }
        public static async ValueTask <QueueDeclareOk> QueueDeclareAsync(this RabbitMQSession session, RabbitMQChannel channel, QueueDeclare queue)
        {
            session.Channels.TryGetValue(channel.ChannelId, out var src);
            var data = session.GetChannelData(channel.ChannelId);

            src.QueueTcs = new TaskCompletionSource <QueueDeclareOk>(TaskCreationOptions.RunContinuationsAsynchronously);
            queue.NoWait = false;
            await session.Writer.SendQueueDeclareAsync(channel.ChannelId, queue).ConfigureAwait(false);

            var declare = await src.QueueTcs.Task.ConfigureAwait(false);

            data.Queues.Add(queue.Name, queue);
            return(declare);
        }
        public static async ValueTask QueueBindAsync(this RabbitMQSession session, RabbitMQChannel channel, QueueBind bind)
        {
            session.Channels.TryGetValue(channel.ChannelId, out var src);
            var data = session.GetChannelData(channel.ChannelId);

            src.CommonTcs = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously);
            await session.Writer.SendQueueBindAsync(channel.ChannelId, bind).ConfigureAwait(false);

            if (bind.NoWait)
            {
                data.Binds.Add(bind.QueueName, bind);
                return;
            }
            await src.CommonTcs.Task.ConfigureAwait(false);

            data.Binds.Add(bind.QueueName, bind);
        }
        public static async ValueTask ExchangeDeclareAsync(this RabbitMQSession session, RabbitMQChannel channel, ExchangeDeclare exchange)
        {
            session.Channels.TryGetValue(channel.ChannelId, out var src);
            var data = session.GetChannelData(channel.ChannelId);

            if (exchange.NoWait)
            {
                await session.Writer.SendExchangeDeclareAsync(channel.ChannelId, exchange).ConfigureAwait(false);

                data.Exchanges.Add(exchange.Name, exchange);
                return;
            }
            src.CommonTcs = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously);
            await session.Writer.SendExchangeDeclareAsync(channel.ChannelId, exchange).ConfigureAwait(false);

            await src.CommonTcs.Task.ConfigureAwait(false);

            data.Exchanges.Add(exchange.Name, exchange);
        }
Exemple #7
0
        internal static async Task ConsumerStartAsync(this RabbitMQSession session, RabbitMQConsumer consumer)
        {
            var data = session.GetChannelData(consumer.Channel.ChannelId);

            if (!consumer.Conf.NoWait)
            {
                data.ConsumeTcs = new TaskCompletionSource <string>(TaskCreationOptions.RunContinuationsAsynchronously);
            }

            await session.Writer.SendBasicConsumeAsync(consumer.Channel.ChannelId, consumer.Conf).ConfigureAwait(false);

            if (!consumer.Conf.NoWait)
            {
                var tag = await data.ConsumeTcs.Task.ConfigureAwait(false);

                if (!tag.Equals(consumer.Conf.ConsumerTag))
                {
                    RabbitMQExceptionHelper.ThrowIfConsumeOkTagMissmatch(consumer.Conf.ConsumerTag, tag);
                }
                consumer.IsClosed = false;
            }
            data.Consumers.Add(consumer.Conf.ConsumerTag, consumer);
        }