Exemplo n.º 1
0
        private void ApplySettings(ConsumerSettings <K, V> updatedSettings)
        {
            _settings         = updatedSettings;
            _pollTimeout      = _settings.PollTimeout;
            _positionTimeout  = _settings.PositionTimeout;
            _commitRefreshing = CommitRefreshing.Create <K, V>(_settings.CommitRefreshInterval);
            try
            {
                if (_log.IsDebugEnabled)
                {
                    _log.Debug($"Creating Kafka consumer with settings: {JsonConvert.SerializeObject(_settings)}");
                }

                var localSelf = Self;
                _consumer = _settings.CreateKafkaConsumer(
                    consumeErrorHandler: (c, e) => localSelf.Tell(new Status.Failure(new KafkaException(e))),
                    partitionAssignedHandler: (c, tp) => localSelf.Tell(new PartitionAssigned(tp.ToImmutableHashSet())),
                    partitionRevokedHandler: (c, tp) => localSelf.Tell(new PartitionRevoked(tp.ToImmutableHashSet())),
                    statisticHandler: (c, json) => _statisticsHandler.OnStatistics(c, json));

                if (_settings.ConnectionCheckerSettings.Enabled)
                {
                    _connectionCheckerActor = Context.ActorOf(ConnectionChecker.Props(_settings.ConnectionCheckerSettings));
                }
            }
            catch (Exception e)
            {
                ProcessError(e);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// KafkaConsumerActor
        /// </summary>
        /// <param name="owner">Owner actor to send critical failures to</param>
        /// <param name="settings">Consumer settings</param>
        /// <param name="partitionEventHandler">Partion events handler</param>
        public KafkaConsumerActor(IActorRef owner, ConsumerSettings <K, V> settings, IPartitionEventHandler <K, V> partitionEventHandler)
        {
            _owner    = owner;
            _settings = settings;
            _partitionEventHandler = partitionEventHandler;

            _pollMessage        = new Internal.Poll <K, V>(this, periodic: true);
            _delayedPollMessage = new Internal.Poll <K, V>(this, periodic: false);
            _log = Context.GetLogger();
            _commitRefreshing = CommitRefreshing.Create <K, V>(_settings.CommitRefreshInterval);
        }