Example #1
0
        private async Task Connect(CancellationToken cancellationToken)
        {
            await Task.Yield();

            try
            {
                while (true)
                {
                    using (var proxy = new ReaderProxy(_stateManager, new AsyncQueue <MessagePackage>()))
                        await using (Stream = await _streamFactory.CreateStream(proxy, cancellationToken))
                        {
                            proxy.Active();
                            await _stateManager.StateChangedFrom(ReaderState.Connected, cancellationToken);

                            if (_stateManager.IsFinalState())
                            {
                                return;
                            }
                        }
                }
            }
            catch (OperationCanceledException)
            {
                HasClosed();
            }
            catch (Exception exception)
            {
                HasFaulted(exception);
            }
        }
Example #2
0
 public Reader(IConsumerStreamFactory streamFactory, IFaultStrategy faultStrategy)
 {
     _stateManager       = new StateManager <ReaderState>(ReaderState.Disconnected, ReaderState.Closed, ReaderState.ReachedEndOfTopic, ReaderState.Faulted);
     _streamFactory      = streamFactory;
     _faultStrategy      = faultStrategy;
     _connectTokenSource = new CancellationTokenSource();
     Stream                  = new NotReadyStream();
     _connectTask            = Connect(_connectTokenSource.Token);
     _throwIfClosedOrFaulted = () => { };
 }
Example #3
0
 public Consumer(IConsumerStreamFactory streamFactory, IFaultStrategy faultStrategy, bool setProxyState)
 {
     _executor           = new Executor(OnException);
     _cachedCommandAck   = new CommandAck();
     _stateManager       = new StateManager <ConsumerState>(ConsumerState.Disconnected, ConsumerState.Closed, ConsumerState.ReachedEndOfTopic, ConsumerState.Faulted);
     _streamFactory      = streamFactory;
     _faultStrategy      = faultStrategy;
     _setProxyState      = setProxyState;
     _connectTokenSource = new CancellationTokenSource();
     Stream                  = new NotReadyStream();
     _connectTask            = Connect(_connectTokenSource.Token);
     _throwIfClosedOrFaulted = () => { };
 }