private static void TestBug1490652SendData(TestHelperOptions testOptions)
        {
            int           correlationID = 0;
            Random        rand          = new Random();
            StringBuilder sb            = new StringBuilder();

            try
            {
                KafkaSimpleManagerConfiguration config = new KafkaSimpleManagerConfiguration()
                {
                    Zookeeper      = testOptions.Zookeeper,
                    MaxMessageSize = SyncProducerConfiguration.DefaultMaxMessageSize
                };
                config.Verify();
                using (KafkaSimpleManager <int, Kafka.Client.Messages.Message> kafkaSimpleManager = new KafkaSimpleManager <int, Kafka.Client.Messages.Message>(config))
                {
                    TopicMetadata topicMetadata = kafkaSimpleManager.RefreshMetadata(0, "ClientID", correlationID++, testOptions.Topic, true);
                    PartitionCount = topicMetadata.PartitionsMetadata.Count();
                    List <ProducerData <int, Message> > listOfDataNeedSendInOneBatch = new List <ProducerData <int, Message> >();
                    for (int i = 0; i < PartitionCount; i++)
                    {
                        TestBug1490652DataSent.Add(i, new Dictionary <int, string>());
                        for (int j = 0; j < TestBug1490652MessageCountPerPartition; j++)
                        {
                            string val  = KafkaClientHelperUtils.GetRandomString(testOptions.MessageSize);
                            byte[] bVal = System.Text.Encoding.UTF8.GetBytes(val);
                            //Set the key to partitionID, so it can directly fall into  that partition.
                            Message message = new Message(bVal, CompressionCodecs.DefaultCompressionCodec);
                            listOfDataNeedSendInOneBatch.Add(new ProducerData <int, Message>(testOptions.Topic, i, message));
                            TestBug1490652DataSent[i].Add(j, val);
                        }
                    }

                    ProducerConfiguration producerConfig = new ProducerConfiguration(new List <BrokerConfiguration>()
                    {
                    })
                    {
                        PartitionerClass = ProducerConfiguration.DefaultPartitioner,
                        RequiredAcks     = 1,
                        BufferSize       = config.BufferSize,
                        ZooKeeper        = config.ZookeeperConfig,
                        MaxMessageSize   = Math.Max(config.MaxMessageSize, Math.Max(SyncProducerConfiguration.DefaultMaxMessageSize, testOptions.MessageSize))
                    };
                    producerConfig.SyncProducerOfOneBroker = 1;
                    Producer <int, Kafka.Client.Messages.Message> producer = new Producer <int, Kafka.Client.Messages.Message>(producerConfig);
                    producer.Send(listOfDataNeedSendInOneBatch);
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Produce data Got exception:{0}\r\ninput parameter: {1}\r\n"
                                   , ex.FormatException(), testOptions.ToString());
            }
        }
        private static void Initializer(ProducePerfTestHelperOption producewrapperOption)
        {
            Logger.InfoFormat("prepare perf test, {0} ", DateTime.Now);
            listOfDataNeedSendInOneBatch = new List <ProducerData <byte[], Message> >();
            for (int i = 0; i < producewrapperOption.MessageCountPerBatch; i++)
            {
                String vKey = KafkaClientHelperUtils.GetRandomString(32);
                byte[] bKey = System.Text.Encoding.UTF8.GetBytes(vKey);

                String val  = KafkaClientHelperUtils.GetRandomString(producewrapperOption.MessageSize);
                byte[] bVal = System.Text.Encoding.UTF8.GetBytes(val);

                Message message = new Message(bVal, bKey, producewrapperOption.CompressionCodec);
                listOfDataNeedSendInOneBatch.Add(new ProducerData <byte[], Message>(producewrapperOption.Topic, message));
            }
        }
Esempio n. 3
0
        private static void PrepareSentMessages(ProduceSimpleHelperOption produceroundrobinOptions)
        {
            Console.WriteLine("start perf test, {0} ", DateTime.Now);
            listOfDataNeedSendInOneBatch = new List <ProducerData <byte[], Message> >();
            for (int i = 0; i < produceroundrobinOptions.MessageCountPerBatch; i++)
            {
                String val  = KafkaClientHelperUtils.GetRandomString(produceroundrobinOptions.MessageSize);
                byte[] bVal = System.Text.Encoding.UTF8.GetBytes(val);
                byte[] bKey = System.Text.Encoding.UTF8.GetBytes(string.Format("{0:000000}", i));
                if (produceroundrobinOptions.ConstantMessageKey)
                {
                    bKey = System.Text.Encoding.UTF8.GetBytes(string.Format("{0:000000}", 0));
                }

                Message message = new Message(bVal, bKey, produceroundrobinOptions.CompressionCodec);
                listOfKeys.Add(bKey);
                listOfDataNeedSendInOneBatch.Add(new ProducerData <byte[], Message>(produceroundrobinOptions.Topic, bKey, message));
            }
        }