示例#1
0
        private async Task Test(CancellationToken cancellationToken)
        {
            int producerCount = _cmdOptions.Count > 0 ? _cmdOptions.Count : 1;
            var duration      = Stopwatch.StartNew();

            for (int i = 0; i < producerCount; i++)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                var messageData = new KafkaMessage {
                    MessageId = i.ToString(), Content = $"KafkaMessage我是内容_{i}", CreateTime = DateTime.Now
                };
                await _messageBus.PublishAsync(messageData);

                //if ((i + 1) % 10000 == 0)
                _logger.LogInformation($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}生产数据KafkaMessage:MessageId={messageData.MessageId}");
            }
            duration.Stop();

            var totalSecond = duration.ElapsedMilliseconds / 1000;//执行任务的时间

            _logger.LogInformation($"生产效率={producerCount * 1.0 / totalSecond}");
        }
示例#2
0
 private void Consume(KafkaMessage item)
 {
     this._logger.LogInformation("messageId={messageId},content = {data}", item.MessageId, item.Content);
 }