示例#1
0
        private static async Task Main()
        {
            Variables.AmountOfMessagesVariable = 25000;
            Variables.BatchTimerVariable       = 20;
            Variables.BatchingSizeVariable     = 2000;
            Variables.IsDev = true;
            const string topic = "Topic3";

            _producer = await ProducerService.Setup("http://localhost");

            var messages       = MessageGenerator.GenerateMessages(Variables.AmountOfMessagesVariable);
            var messageHeaders = await _producer.GetMessageHeaders(messages, topic);

            while (_run)
            {
                var sw = new Stopwatch();
                sw.Reset();
                sw.Start();

                var tasks = Enumerable.Range(0, messageHeaders.Length).Select(i => _producer.Publish(messageHeaders[i], messages[i]));
                await Task.WhenAll(tasks);

                sw.Stop();
                Console.WriteLine($"Sent messages in elapsed in {sw.ElapsedMilliseconds} milliseconds");

                await Task.Delay(1000); //Delay added for test of timer on batches
            }
        }
示例#2
0
        private static async Task Main()
        {
            Console.WriteLine("This is the new version 3");
            var amountOfMessagesVariable = EnvironmentVariables.AmountOfMessagesVariable;
            var batchingSizeVariable     = EnvironmentVariables.BatchingSizeVariable;

            var producer = new ProducerService(new Serializer(), new BatchingService(batchingSizeVariable));

            const string topic = "Topic2";
            int          partitionCount;

            if (EnvironmentVariables.IsDev)
            {
                await producer.InitSocketLocalhost();

                partitionCount = 10;
            }
            else
            {
                var metricServer = new MetricServer(80);
                metricServer.Start();
                var client = EnvironmentVariables.IsDev ? new EtcdClient("http://localhost") : new EtcdClient("http://etcd");
                await producer.InitSockets(client);

                partitionCount = await TopicList.GetPartitionCount(client, topic);
            }

            AppDomain.CurrentDomain.ProcessExit += async(sender, e) => await producer.CloseConnections();

            while (true)
            {
                var(messageHeaders, messages) = MessageGenerator.GenerateMessages(amountOfMessagesVariable, partitionCount, topic);

                for (var i = 0; i < messageHeaders.Length; i++)
                {
                    await producer.Publish(messageHeaders[i], messages[i]);
                }

                await Task.Delay(15 * 1000); //Delay added for test of timer on batches
            }
        }