/// <inheritdoc />
        protected override IActorRef CreateConsumerActor()
        {
            var partitionsAssignedHandler = GetAsyncCallback <IEnumerable <TopicPartition> >(PartitionsAssigned);
            var partitionsRevokedHandler  = GetAsyncCallback <IEnumerable <TopicPartitionOffset> >(PartitionsRevoked);

            IPartitionEventHandler internalHandler = new PartitionEventHandlers.AsyncCallbacks(partitionsAssignedHandler, partitionsRevokedHandler);

            // If custom partition events handler specified - add it to the chain
            var eventHandler = _subscription is IAutoSubscription autoSubscription && autoSubscription.PartitionEventsHandler.HasValue
                ? new PartitionEventHandlers.Chain(autoSubscription.PartitionEventsHandler.Value, internalHandler)
                : internalHandler;

            IStatisticsHandler statisticsHandler = _subscription.StatisticsHandler.HasValue
                ? _subscription.StatisticsHandler.Value
                : new StatisticsHandlers.Empty();

            // This allows to override partition events handling by subclasses
            eventHandler = AddToPartitionAssignmentHandler(eventHandler);

            if (!(Materializer is ActorMaterializer actorMaterializer))
            {
                throw new ArgumentException($"Expected {typeof(ActorMaterializer)} but got {Materializer.GetType()}");
            }

            var extendedActorSystem = actorMaterializer.System.AsInstanceOf <ExtendedActorSystem>();
            var actor = extendedActorSystem.SystemActorOf(KafkaConsumerActorMetadata.GetProps(SourceActor.Ref, _settings, eventHandler, statisticsHandler),
                                                          $"kafka-consumer-{_actorNumber}");

            return(actor);
        }
示例#2
0
        /// <inheritdoc />
        protected override IActorRef CreateConsumerActor()
        {
            var partitionsAssignedHandler = GetAsyncCallback <IEnumerable <TopicPartition> >(PartitionsAssigned);
            var partitionsRevokedHandler  = GetAsyncCallback <IEnumerable <TopicPartitionOffset> >(PartitionsRevoked);

            IPartitionEventHandler <K, V> eventHandler = new AsyncCallbacksPartitionEventHandler <K, V>(partitionsAssignedHandler, partitionsRevokedHandler);

            // This allows to override partition events handling by subclasses
            eventHandler = AddToPartitionAssignmentHandler(eventHandler);

            if (!(Materializer is ActorMaterializer actorMaterializer))
            {
                throw new ArgumentException($"Expected {typeof(ActorMaterializer)} but got {Materializer.GetType()}");
            }

            var extendedActorSystem = actorMaterializer.System.AsInstanceOf <ExtendedActorSystem>();
            var actor = extendedActorSystem.SystemActorOf(KafkaConsumerActorMetadata.GetProps(SourceActor.Ref, _settings, eventHandler),
                                                          $"kafka-consumer-{_actorNumber}");

            return(actor);
        }