Kafka.Client.Consumers.ZookeeperConsumerConnector.CreateMessageStreams C# (CSharp) Method

CreateMessageStreams() public method

Creates a list of message streams for each topic.
Explicitly triggers load balancing for this consumer
public CreateMessageStreams ( int>.IDictionary topicCountDict ) : IList>.IDictionary
topicCountDict int>.IDictionary /// The map of topic on number of streams ///
return IList>.IDictionary
        public IDictionary<string, IList<KafkaMessageStream>> CreateMessageStreams(IDictionary<string, int> topicCountDict)
        {
            this.EnsuresNotDisposed();
            return this.Consume(topicCountDict);
        }

Usage Example

Exemplo n.º 1
0
        public void ConsumerPerformsRebalancingWhenConsumerIsRemovedAndTakesItsPartitions()
        {
            var config = new ConsumerConfig(clientConfig)
            {
                AutoCommit = false,
                GroupId = "group1",
                ZkSessionTimeoutMs = 60000,
                ZkConnectionTimeoutMs = 60000
            };

            IList<string> ids;
            IList<string> owners;
            using (var consumerConnector = new ZookeeperConsumerConnector(config, true))
            {
                var client = ReflectionHelper.GetInstanceField<ZooKeeperClient>("zkClient", consumerConnector);
                Assert.IsNotNull(client);
                client.DeleteRecursive("/consumers/group1");
                var topicCount = new Dictionary<string, int> { { "test", 1 } };
                consumerConnector.CreateMessageStreams(topicCount);
                WaitUntillIdle(client, 1000);
                using (var consumerConnector2 = new ZookeeperConsumerConnector(config, true))
                {
                    consumerConnector2.CreateMessageStreams(topicCount);
                    WaitUntillIdle(client, 1000);
                    ids = client.GetChildren("/consumers/group1/ids", false).ToList();
                    owners = client.GetChildren("/consumers/group1/owners/test", false).ToList();
                    Assert.That(ids, Is.Not.Null.And.Not.Empty);
                    Assert.That(ids.Count, Is.EqualTo(2));
                    Assert.That(owners, Is.Not.Null.And.Not.Empty);
                    Assert.That(owners.Count, Is.EqualTo(2));
                }

                WaitUntillIdle(client, 1000);
                ids = client.GetChildren("/consumers/group1/ids", false).ToList();
                owners = client.GetChildren("/consumers/group1/owners/test", false).ToList();

                Assert.That(ids, Is.Not.Null.And.Not.Empty);
                Assert.That(ids.Count, Is.EqualTo(1));
                Assert.That(owners, Is.Not.Null.And.Not.Empty);
                Assert.That(owners.Count, Is.EqualTo(2));

                var data1 = client.ReadData<string>("/consumers/group1/owners/test/" + owners[0], false);
                var data2 = client.ReadData<string>("/consumers/group1/owners/test/" + owners[1], false);

                Assert.That(data1, Is.Not.Null.And.Not.Empty);
                Assert.That(data2, Is.Not.Null.And.Not.Empty);
                Assert.That(data1, Is.EqualTo(data2));
                Assert.That(data1, Is.StringStarting(ids[0]));
            }
        }
All Usage Examples Of Kafka.Client.Consumers.ZookeeperConsumerConnector::CreateMessageStreams