Пример #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;
            }
        }
        private void WithCheckerActorRef(Action <IActorRef> block)
        {
            var checker = ChildActorOf(ConnectionChecker.Props(_config));

            block(checker);
            Sys.Stop(Watch(checker));
            ExpectTerminated(checker);
        }
        private T WithCheckerActorRef <T>(Func <IActorRef, T> block)
        {
            var checker = ChildActorOf(ConnectionChecker.Props(_config));
            var res     = block(checker);

            Sys.Stop(Watch(checker));
            ExpectTerminated(checker);
            return(res);
        }