Пример #1
0
        /// <summary>
        /// Create a reader.
        /// </summary>
        public IReader CreateReader(ReaderOptions options)
        {
            ThrowIfDisposed();

            var correlationId = Guid.NewGuid();
            var executor      = new Executor(correlationId, _processManager, _exceptionHandler);
            var subscribe     = new CommandSubscribe
            {
                ConsumerName   = options.ReaderName,
                Durable        = false,
                ReadCompacted  = options.ReadCompacted,
                StartMessageId = options.StartMessageId.ToMessageIdData(),
                Subscription   = $"Reader-{Guid.NewGuid():N}",
                Topic          = options.Topic
            };
            var messagePrefetchCount  = options.MessagePrefetchCount;
            var batchHandler          = new BatchHandler(false);
            var decompressorFactories = CompressionFactories.DecompressorFactories();
            var factory      = new ConsumerChannelFactory(correlationId, _processManager, _connectionPool, executor, subscribe, messagePrefetchCount, batchHandler, decompressorFactories);
            var stateManager = new StateManager <ReaderState>(ReaderState.Disconnected, ReaderState.Closed, ReaderState.ReachedEndOfTopic, ReaderState.Faulted);
            var reader       = new Reader(correlationId, ServiceUrl, options.Topic, _processManager, new NotReadyChannel(), executor, stateManager);

            if (options.StateChangedHandler is not null)
            {
                _ = StateMonitor.MonitorReader(reader, options.StateChangedHandler);
            }
            var process = new ReaderProcess(correlationId, stateManager, factory, reader);

            _processManager.Add(process);
            process.Start();
            return(reader);
        }
Пример #2
0
        /// <summary>
        /// Create a reader.
        /// </summary>
        public IReader CreateReader(ReaderOptions options)
        {
            ThrowIfDisposed();
            var correlationId = Guid.NewGuid();
            var executor      = new Executor(correlationId, _processManager, _exceptionHandler);
            var factory       = new ReaderChannelFactory(correlationId, _processManager, _connectionPool, executor, options);
            var stateManager  = new StateManager <ReaderState>(ReaderState.Disconnected, ReaderState.Closed, ReaderState.ReachedEndOfTopic, ReaderState.Faulted);
            var reader        = new Reader(correlationId, options.Topic, _processManager, new NotReadyChannel(), executor, stateManager);

            if (options.StateChangedHandler is not null)
            {
                _ = StateMonitor.MonitorReader(reader, options.StateChangedHandler);
            }
            var process = new ReaderProcess(correlationId, stateManager, factory, reader);

            _processManager.Add(process);
            process.Start();
            return(reader);
        }