在 Kafka 客户端 (consumers/producers) 宕机后恢复它们

Recovering Kafka clients (consumers/producers) after they went down

在我工作的公司,我们使用 Spring for Kafka 没有身份验证,最近我们做了一些实验来设置 Kafka 的安全性,我们启用了短暂的身份验证,这导致我们所有 consumers/producers 在我们的微服务中! (微服务保持正常)

异常:

Authorization Exception and no authorizationExceptionRetryInterval set

org.apache.kafka.common.errors.GroupAuthorizationException: Not authorized to access group: foo-group

经过一些研究,我们发现这是 kafka 客户端的预期行为,我们需要设置 authorizationExceptionRetryInterval 属性

public void setAuthorizationExceptionRetryInterval​(java.time.Duration authorizationExceptionRetryInterval)

Set the interval between retries after AuthorizationException is thrown by KafkaConsumer. By default the field is null and retries are disabled. In such case the container will be stopped. The interval must be less than max.poll.interval.ms consumer property.

这是一些其他有用的链接

我想知道的是:

  1. 身份验证失败是唯一的情况吗 consumers/producers 下降 ?
  2. 如果还有其他一些情况,如何确保我们的 consumers/producers 无需人工干预即可恢复(重新启动 微服务)?换句话说,如何检查 consumers/producers 启动并重新启动它们?

容器仅在以下情况下停止:

  • AuthorizationException 没有 authorizationExceptionRetryInterval
  • NoOffsetForPartitionException - 当 ConsumerConfig.AUTO_OFFSET_RESET_CONFIG 不是 earliestlatest 并且此消费者组的分区没有现有偏移量时抛出。
  • FencedInstanceIdException - 使用事务和静态组成员(意味着其他实例正在使用此实例 ID)。
  • StopAfterFenceException - 当 stopContainerWhenFenced 为真时(默认为假) - 仅适用于交易
  • 任何Error(例如OOME)