Example #1
0
        protected override void PostStop()
        {
            base.PostStop();
            try
            {
                _pollCancellation?.Cancel(); // Stop existing scheduling, if any

                if (_settings.ConnectionCheckerSettings.Enabled)
                {
                    _connectionCheckerActor.Tell(KafkaConsumerActorMetadata.Internal.Stop.Instance);
                }

                // reply to outstanding requests is important if the actor is restarted
                foreach (var(actorRef, request) in _requests.ToTuples())
                {
                    var emptyMessages = new KafkaConsumerActorMetadata.Internal.Messages <K, V>(request.RequestId,
                                                                                                ImmutableList <ConsumeResult <K, V> > .Empty);
                    actorRef.Tell(emptyMessages);
                }

                RebalancePostStop();
            }
            finally
            {
                // Make sure that the consumer is unassigned from the partition AND closed before we dispose
                try { _consumer.Unassign(); }
                catch (Exception) { /* no-op */ }

                try { _consumer.Close(); }
                catch (Exception) { /* no-op */ }

                _consumer.Dispose();
            }
        }
Example #2
0
        protected override void PostStop()
        {
            // reply to outstanding requests is important if the actor is restarted
            foreach (var(actorRef, request) in _requests.ToTuples())
            {
                var emptyMessages = new KafkaConsumerActorMetadata.Internal.Messages <K, V>(request.RequestId, ImmutableList <ConsumeResult <K, V> > .Empty);
                actorRef.Tell(emptyMessages);
            }

            _partitionAssignmentHandler.PostStop();

            _consumer.Dispose();

            base.PostStop();
        }