在我工作的公司,我们使用 Spring for Kafka
没有身份验证,最近我们做了一些实验来设置 Kafka 的安全性,我们启用了短暂的身份验证,这导致我们所有的迷恋我们微服务中的消费者/生产者! (微服务保持正常)
异常:
Authorization Exception and no authorizationExceptionRetryInterval set
org.apache.kafka.common.errors.GroupAuthorizationException: Not authorized to access group: foo-group
经过一些研究,我们发现这是 kafka 客户端的预期行为,我们需要设置 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.
这是一些其他有用的链接
Setting authorizationExceptionRetryInterval for Spring Kafka
Why does the spring KafkaConsumer suspend all consumption from n topics when one fails to authorize
我想知道的是:
- 身份验证失败是唯一的情况吗 消费者/生产者下降?
- 如果还有一些其他情况,如何确保我们的 消费者/生产者无需人为干预即可恢复(重新启动 微服务)?换句话说,如何检查 消费者/生产者启动并重新启动它们?
最佳答案
容器仅在以下情况下停止:
AuthorizationException
没有authorizationExceptionRetryInterval
NoOffsetForPartitionException
- 当ConsumerConfig.AUTO_OFFSET_RESET_CONFIG
不是earliest
或latest
并且没有现有偏移量时抛出与这个消费者群体的分区。FencedInstanceIdException
- 使用事务和静态组成员(意味着其他一些实例正在使用此实例 ID)。StopAfterFenceException
- 当stopContainerWhenFenced
为真(默认为 false)时 - 仅适用于交易- 任何
错误
(例如 OOME)
关于spring-boot - 在 Kafka 客户(消费者/生产者)宕机后恢复它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66519618/