Esempio n. 1
0
        private void HandleCommand(uint commandSize, ReadOnlySequence <byte> sequence)
        {
            var command = Serializer.Deserialize <BaseCommand>(sequence.Slice(0, commandSize));

            switch (command.CommandType)
            {
            case BaseCommand.Type.Message:
                _consumerManager.Incoming(command.Message, sequence.Slice(commandSize));
                return;

            case BaseCommand.Type.CloseConsumer:
                _consumerManager.Incoming(command.CloseConsumer);
                return;

            case BaseCommand.Type.ActiveConsumerChange:
                _consumerManager.Incoming(command.ActiveConsumerChange);
                return;

            case BaseCommand.Type.ReachedEndOfTopic:
                _consumerManager.Incoming(command.ReachedEndOfTopic);
                return;

            case BaseCommand.Type.CloseProducer:
                _producerManager.Incoming(command.CloseProducer);
                return;

            case BaseCommand.Type.Ping:
                _pingPongHandler.Incoming(command.Ping);
                return;

            default:
                _requestResponseHandler.Incoming(command);
                return;
            }
        }
Esempio n. 2
0
        public async Task ProcessIncommingFrames(CancellationToken cancellationToken)
        {
            await Task.Yield();

            try
            {
                await foreach (var frame in _stream.Frames())
                {
                    var commandSize = frame.ReadUInt32(0, true);
                    var command     = Serializer.Deserialize <BaseCommand>(frame.Slice(4, commandSize));

                    switch (command.CommandType)
                    {
                    case BaseCommand.Type.Message:
                        _channelManager.Incoming(command.Message, frame.Slice(commandSize + 4));
                        break;

                    case BaseCommand.Type.CloseConsumer:
                        _channelManager.Incoming(command.CloseConsumer);
                        break;

                    case BaseCommand.Type.ActiveConsumerChange:
                        _channelManager.Incoming(command.ActiveConsumerChange);
                        break;

                    case BaseCommand.Type.ReachedEndOfTopic:
                        _channelManager.Incoming(command.ReachedEndOfTopic);
                        break;

                    case BaseCommand.Type.CloseProducer:
                        _channelManager.Incoming(command.CloseProducer);
                        break;

                    case BaseCommand.Type.Ping:
                        _pingPongHandler.Incoming(command.Ping, cancellationToken);
                        break;

                    default:
                        _requestResponseHandler.Incoming(command);
                        break;
                    }
                }
            }
            catch
            {
                // ignored
            }
        }