【问题标题】:Kafka consumers unable to send heartbeat but receives messagesKafka消费者无法发送心跳但收到消息
【发布时间】:2019-10-13 05:10:09
【问题描述】:

我在 Azure (https://bitnami.com/stack/kafka/cloud/azure) 上使用来自 Bitnami 的 Kafka 集群。它是一个单节点集群,在一个 VM 上具有代理,在另一个 VM 上具有 Zookeeper。我已启用端口 9090 和 2181。

我有 .Net Core WebApps 在 azure 上运行,带有适用于 Kafka 的 Confluent .NET Client (v1.0.0)。 WebApp 配置了生产者和消费者。

我面临的问题是,在启动网络应用程序后不久,消费者由于心跳过期而失败。但它同时能够接收到来自生产者的一些消息。即使我只启动一个 Consumer,它也会在 SessionTimeoutMs 后由于心跳过期而自动失败。

我无法理解为什么心跳会过期(消费者正在接收消息)。它是否发生在单独的端口上?如果我设置 SessionTimeoutMs = 300000(最大值),它会在 5 分钟后过期。

服务器日志(当我在 WebApp 中添加消费者时 - 请注意心跳在 16 秒内过期):

[2019-05-22 17:57:42,302] INFO [GroupCoordinator 1001]: Preparing to rebalance group test-consumer-group-new2 in state PreparingRebalance with old generation 4 (__consumer_offsets-40) (reason: Adding new member rdkafka-03f8db78-4f74-4cb2-9389-bb949c53281c) (kafka.coordinator.group.GroupCoordinator)
[2019-05-22 17:57:42,303] INFO [GroupCoordinator 1001]: Stabilized group test-consumer-group-new2 generation 5 (__consumer_offsets-40) (kafka.coordinator.group.GroupCoordinator)
[2019-05-22 17:57:42,349] INFO [GroupCoordinator 1001]: Assignment received from leader for group test-consumer-group-new2 for generation 5 (kafka.coordinator.group.GroupCoordinator)
[2019-05-22 17:57:58,403] INFO [GroupCoordinator 1001]: Member rdkafka-03f8db78-4f74-4cb2-9389-bb949c53281c in group test-consumer-group-new2 has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator)
[2019-05-22 17:57:58,403] INFO [GroupCoordinator 1001]: Preparing to rebalance group test-consumer-group-new2 in state PreparingRebalance with old generation 5 (__consumer_offsets-40) (reason: removing member rdkafka-03f8db78-4f74-4cb2-9389-bb949c53281c on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator)
[2019-05-22 17:57:58,404] INFO [GroupCoordinator 1001]: Group test-consumer-group-new2 with generation 6 is now empty (__consumer_offsets-40) (kafka.coordinator.group.GroupCoordinator)

我的 server.properties:

listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://40.X.X.X:9092

消费者的配置:

var conf = new ConsumerConfig
{
    GroupId = "test-consumer-group-new2",
    BootstrapServers = "40.X.X.X:9092",
    SecurityProtocol = SecurityProtocol.Plaintext,
    SaslMechanism = SaslMechanism.Plain,
    SaslUsername = "user",
    SaslPassword = "<passowrd>"
}

我也不了解 Kafka 中的新旧世代,也找不到相关文档。任何人都可以解释一下吗?谢谢。

【问题讨论】:

  • Bitnami 工程师在这里。我们使用默认值配置 Kafka。您将需要调整参数以使用您的应用程序。如果您发现配置 Kafka 的更好价值,请告诉我们,以便我们根据您的反馈改进解决方案。
  • @JotaMartos 即使使用默认值,你知道为什么心跳会在网络上过期吗? (在与代理相同的机器上,生产者和消费者工作得很好)。

标签: .net azure apache-kafka bitnami confluent-platform


【解决方案1】:

max.poll.records - 可能需要减少;

注意heartbeat.interval.ms - 该值必须设置为低于session.timeout.ms,但通常应设置为不高于该值的 1/3

【讨论】:

  • 是的,所有这些都设置为默认值。
猜你喜欢
  • 2021-06-06
  • 2016-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-16
  • 2018-09-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多