Ejemplo n.º 1
0
        /// <summary>
        /// Create a consumer.
        /// </summary>
        public IConsumer CreateConsumer(ConsumerOptions options)
        {
            ThrowIfDisposed();

            var correlationId = Guid.NewGuid();
            var executor      = new Executor(correlationId, _processManager, _exceptionHandler);
            var subscribe     = new CommandSubscribe
            {
                ConsumerName    = options.ConsumerName,
                InitialPosition = (CommandSubscribe.InitialPositionType)options.InitialPosition,
                PriorityLevel   = options.PriorityLevel,
                ReadCompacted   = options.ReadCompacted,
                Subscription    = options.SubscriptionName,
                Topic           = options.Topic,
                Type            = (CommandSubscribe.SubType)options.SubscriptionType
            };
            var messagePrefetchCount  = options.MessagePrefetchCount;
            var batchHandler          = new BatchHandler(true);
            var decompressorFactories = CompressionFactories.DecompressorFactories();
            var factory      = new ConsumerChannelFactory(correlationId, _processManager, _connectionPool, executor, subscribe, messagePrefetchCount, batchHandler, decompressorFactories);
            var stateManager = new StateManager <ConsumerState>(ConsumerState.Disconnected, ConsumerState.Closed, ConsumerState.ReachedEndOfTopic, ConsumerState.Faulted);
            var consumer     = new Consumer(correlationId, ServiceUrl, options.SubscriptionName, options.Topic, _processManager, new NotReadyChannel(), executor, stateManager);

            if (options.StateChangedHandler is not null)
            {
                _ = StateMonitor.MonitorConsumer(consumer, options.StateChangedHandler);
            }
            var process = new ConsumerProcess(correlationId, stateManager, factory, consumer, options.SubscriptionType == SubscriptionType.Failover);

            _processManager.Add(process);
            process.Start();
            return(consumer);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a consumer.
        /// </summary>
        public IConsumer CreateConsumer(ConsumerOptions options)
        {
            ThrowIfDisposed();
            var correlationId = Guid.NewGuid();
            var executor      = new Executor(correlationId, _processManager, _exceptionHandler);
            var factory       = new ConsumerChannelFactory(correlationId, _processManager, _connectionPool, executor, options);
            var stateManager  = new StateManager <ConsumerState>(ConsumerState.Disconnected, ConsumerState.Closed, ConsumerState.ReachedEndOfTopic, ConsumerState.Faulted);
            var consumer      = new Consumer(correlationId, options.Topic, _processManager, new NotReadyChannel(), executor, stateManager);

            if (options.StateChangedHandler is not null)
            {
                _ = StateMonitor.MonitorConsumer(consumer, options.StateChangedHandler);
            }
            var process = new ConsumerProcess(correlationId, stateManager, factory, consumer, options.SubscriptionType == SubscriptionType.Failover);

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