Exemplo n.º 1
0
        public async Task <SubscribeResponse> Send(CommandSubscribe command, IChannel channel, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            Task <SubscribeResponse>?responseTask;

            using (await _lock.Lock(cancellationToken).ConfigureAwait(false))
            {
                responseTask = _channelManager.Outgoing(command, channel);
                var sequence = Serializer.Serialize(command.AsBaseCommand());
                await _stream.Send(sequence).ConfigureAwait(false);
            }

            return(await responseTask.ConfigureAwait(false));
        }
Exemplo n.º 2
0
        public async Task <SubscribeResponse> Send(CommandSubscribe command, IChannel channel)
        {
            Task <SubscribeResponse>?responseTask = null;

            using (await _lock.Lock())
            {
                var baseCommand         = command.AsBaseCommand();
                var requestResponseTask = _requestResponseHandler.Outgoing(baseCommand);
                responseTask = _channelManager.Outgoing(command, requestResponseTask, channel);
                var sequence = Serializer.Serialize(baseCommand);
                await _stream.Send(sequence);
            }

            return(await responseTask);
        }
Exemplo n.º 3
0
        public async Task <SubscribeResponse> Send(CommandSubscribe command, IConsumerProxy proxy)
        {
            Task <BaseCommand>?responseTask = null;

            using (await _lock.Lock())
            {
                _consumerManager.Outgoing(command, proxy);
                var baseCommand = command.AsBaseCommand();
                responseTask = _requestResponseHandler.Outgoing(baseCommand);
                var sequence = Serializer.Serialize(baseCommand);
                await _stream.Send(sequence);
            }

            var response = await responseTask;

            if (response.CommandType == BaseCommand.Type.Error)
            {
                _consumerManager.Remove(command.ConsumerId);
                response.Error.Throw();
            }

            return(new SubscribeResponse(command.ConsumerId));
        }