コード例 #1
0
        public static async ValueTask QueueUnbindAsync(this RabbitMQSession session, RabbitMQChannel channel, QueueUnbind unbind)
        {
            session.Channels.TryGetValue(channel.ChannelId, out var src);
            src.CommonTcs = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously);
            await session.Writer.SendQueueUnbindAsync(channel.ChannelId, unbind).ConfigureAwait(false);

            await src.CommonTcs.Task.ConfigureAwait(false);
        }
コード例 #2
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);
        }
コード例 #3
0
 internal RabbitMQConnection(RabbitMQConnectionFactoryBuilder builder)
 {
     _builder             = builder;
     _logger              = _builder.Logger;
     _channels            = new ConcurrentDictionary <ushort, RabbitMQChannel>();
     _connectionClosedSrc = new TaskCompletionSource <CloseInfo>(TaskCreationOptions.RunContinuationsAsynchronously);
     _lockEvent           = new ManualResetEventSlim(true);
     _session             = new RabbitMQSession(_builder, _channels, _connectionClosedSrc, _lockEvent);
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        private async ValueTask ReconnectAsync(object?obj)
        {
            _logger.LogDebug($"{nameof(RabbitMQConnection)}: begin reconnect");
            try
            {
                _connectionClosedSrc = new TaskCompletionSource <CloseInfo>(TaskCreationOptions.RunContinuationsAsynchronously);
                _watchTask           = Task.Run(WatchAsync).ContinueWith(ReconnectAsync);
                await _session.DisposeAsync().ConfigureAwait(false);

                _session = new RabbitMQSession(_builder, _channels, _connectionClosedSrc, _lockEvent);
                await _session.ConnectWithRecovery().ConfigureAwait(false);
            }
            catch (Exception e)
            {
                _logger.LogDebug($"{nameof(RabbitMQConnection)}: reconnect failed with exception message {e.Message}");
                _connectionClosedSrc.SetException(e);
                Debugger.Break();
            }
            _lockEvent.Set();
            _logger.LogDebug($"{nameof(RabbitMQConnection)}: end reconnect");
        }
コード例 #10
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);
        }
コード例 #11
0
 public static ValueTask PublishBodyAsync(this RabbitMQSession session, ushort channelId, IEnumerable <ReadOnlyMemory <byte> > batch, CancellationToken token = default)
 {
     return(session.Writer.WriteManyAsync(new BodyFrameWriter(channelId), batch, token));
 }
コード例 #12
0
        internal static ValueTask PublishPartialAsync(this RabbitMQSession session, ushort channelId, PublishPartialInfo info, CancellationToken token = default)
        {
            var writer = new PublishInfoAndContentWriter(channelId);

            return(session.Writer.WriteAsync(writer, info, token));
        }
コード例 #13
0
 internal static ValueTask PublishAllAsync(this RabbitMQSession session, PublishAllInfo info, CancellationToken token = default)
 {
     return(session.Writer.WriteAsync(_fullWriter, info, token));
 }
コード例 #14
0
 internal RabbitMQChannel(ushort id, RabbitMQSession session) : base(session)
 {
     ChannelId     = id;
     _publishBatch = new ReadOnlyMemory <byte> [_publishBatchSize];
 }
コード例 #15
0
 internal ChannelData(RabbitMQSession session)
 {
     Session = session;
 }