我们实现了一个kafka用户,该用户在azure应用服务中作为webjob连续运行。但是,我们现在已经观察到使用方正在导致CPU过多。 我们正在使用融合的kafka和librdkafka.redist的1.1.0版本。
下面是我的消费者代码段
var consumerConfig = new ConsumerConfig
{
BootstrapServers = kafkaUri,
EnableAutoCommit = false,
GroupId = consumerGroup,
AutoOffsetReset = AutoOffsetReset.Earliest,
StatisticsIntervalMs = 5000,
SessionTimeoutMs = 6000
};
const int commitPeriod = 10;
using (var c = new ConsumerBuilder<Ignore, string>(consumerConfig).Build())
{
c.Subscribe(kafkaTopic);
try
{
while (true)
{
try
{
Console.WriteLine("Consumer running, waiting for messages");
var msg = c.Consume();
Console.WriteLine($"Consumed message '{msg.Value}' at: '{msg.TopicPartitionOffset}'.");
if (msg.Offset % commitPeriod == 0)
{
{
c.Commit(msg);
}
catch (KafkaException e)
{
Console.WriteLine($"Commit error: {e.Error.Reason}");
}
}
}
catch (ConsumeException e)
{
Console.WriteLine($"Error occured: {e.Error.Reason}");
Log.Error(e.Error.Reason);
}
}
}
}