Beispiel #1
0
        private async ValueTask OnTopicsExtended(ICollection <string> topicsExtended)
        {
            if (topicsExtended.Count == 0 || !topicsExtended.Contains(Topic))
            {
                return;
            }
            var topicName = TopicName.Get(Topic);

            var result = await _lookup.Ask <AskResponse>(new GetPartitionedTopicMetadata(topicName));

            if (result.Failed)
            {
                throw result.Exception;
            }
            var metadata               = result.ConvertTo <PartitionedTopicMetadata>();
            var topics                 = GetPartitionsForTopic(topicName, metadata).ToList();
            var oldPartitionNumber     = _topicMetadata.NumPartitions();
            var currentPartitionNumber = topics.Count;

            if (_log.IsDebugEnabled)
            {
                _log.Debug($"[{Topic}] partitions number. old: {oldPartitionNumber}, new: {currentPartitionNumber}");
            }
            if (oldPartitionNumber == currentPartitionNumber)
            {
                return;
            }
            else if (oldPartitionNumber < currentPartitionNumber)
            {
                var newPartitions = topics.GetRange(oldPartitionNumber, currentPartitionNumber);
                foreach (var partitionName in newPartitions)
                {
                    var producerId = await _generator.Ask <long>(NewProducerId.Instance);

                    var partitionIndex = TopicName.GetPartitionIndex(partitionName);
                    var producer       = _context.ActorOf(Props.Create(() => new ProducerActor <T>(producerId, Client, _lookup, _cnxPool, _generator, partitionName, Conf, partitionIndex, Schema, Interceptors, ClientConfiguration)));
                    var co             = await producer.Ask <AskResponse>(Connect.Instance, ClientConfiguration.OperationTimeout);

                    if (!co.Failed)
                    {
                        _producers.Add(producer);
                        var routee = Routee.FromActorRef(producer);
                        _router.Tell(new AddRoutee(routee));
                    }
                }
                if (_log.IsDebugEnabled)
                {
                    _log.Debug($"[{Topic}] success create producers for extended partitions. old: {oldPartitionNumber}, new: {currentPartitionNumber}");
                }
                _topicMetadata = new TopicMetadata(currentPartitionNumber);
            }
            else
            {
                _log.Error($"[{Topic}] not support shrink topic partitions. old: {oldPartitionNumber}, new: {currentPartitionNumber}");
            }
        }
        public Streamer()
        {
            RequestStrategy = new InFlightStrategy(this);

            var routees = new[]
            {
                Routee.FromActorRef(Context.ActorOf(Props.Create <Worker>().WithDispatcher(Context.Props.Dispatcher))),
                Routee.FromActorRef(Context.ActorOf(Props.Create <Worker>().WithDispatcher(Context.Props.Dispatcher))),
                Routee.FromActorRef(Context.ActorOf(Props.Create <Worker>().WithDispatcher(Context.Props.Dispatcher)))
            };

            _router = new Router(new RoundRobinRoutingLogic(), routees);
        }
Beispiel #3
0
        private async ValueTask Start()
        {
            Exception createFail = null;
            var       completed  = 0;

            for (var partitionIndex = 0; partitionIndex < _topicMetadata.NumPartitions(); partitionIndex++)
            {
                var producerId = await _generator.Ask <long>(NewProducerId.Instance);

                var partitionName = TopicName.Get(Topic).GetPartition(partitionIndex).ToString();
                var producer      = _context.ActorOf(Props.Create(() => new ProducerActor <T>(producerId, Client, _lookup, _cnxPool, _generator, partitionName, Conf, partitionIndex, Schema, Interceptors, ClientConfiguration)));
                var co            = await producer.Ask <AskResponse>(Connect.Instance, ClientConfiguration.OperationTimeout);

                if (!co.Failed)
                {
                    _producers.Add(producer);
                    var routee = Routee.FromActorRef(producer);
                    _router.Tell(new AddRoutee(routee));
                }
                else
                {
                    State.ConnectionState = HandlerState.State.Failed;
                    createFail            = co.Exception;
                }
                if (++completed == _topicMetadata.NumPartitions())
                {
                    if (createFail == null)
                    {
                        State.ConnectionState = HandlerState.State.Ready;
                        _log.Info($"[{Topic}] Created partitioned producer");
                        Sender.Tell(co);
                    }
                    else
                    {
                        _log.Error($"[{Topic}] Could not create partitioned producer: {createFail}");
                        Sender.Tell(createFail);
                        Client.Tell(new CleanupProducer(_self));
                    }
                }
            }
        }
Beispiel #4
0
 public ConsistentMapGroup(IDictionary <string, IActorRef> keyedActors) : this(keyedActors.ToDictionary(p => p.Key, p => p.Value.Path.ToString()))
 {
     _routees = keyedActors.ToDictionary(p => p.Key, p => Routee.FromActorRef(p.Value));
 }