如何设置 spring-cloud-stream kafka 重连频率?

How to set spring-cloud-stream kafka reconnect frequency?

有没有办法在 spring 云流 kafka 活页夹中设置重新连接频率或两次重新连接尝试之间的时间?

万一 kafka 集群在应用程序处于 运行 时出现故障,它会不断尝试重新连接并且 CPU 使用率上升到 100%。

我可以在 KafkaConsumerProperties.java 中看到 属性 recoveryInterval(spring-cloud-stream-binder-kafka-core-3.0 的一部分。6.RELEASE), 但评论说它已被弃用,活页夹不使用它。我可以使用其他 属性 吗?

编辑: 这是我设置 属性 的方式(根据 this):

# in application.properties
spring.cloud.stream.kafka.streams.binder.configuration.reconnect.backoff.ms=5000
spring.cloud.stream.kafka.streams.binder.configuration.reconnect.backoff.max.ms=10000

我也试过直接设置,但是还是不行。

reconnect.backoff.ms=5000
reconnect.backoff.max.ms=10000

编辑 2:

这样设置就可以了。但是 CPU 使用率仍然上升到 100%。

# in application.properties
spring.cloud.stream.kafka.binder.configuration.reconnect.backoff.ms=5000
spring.cloud.stream.kafka.binder.configuration.reconnect.backoff.max.ms=10000

https://kafka.apache.org/documentation/#streamsconfigs_reconnect.backoff.ms

The base amount of time to wait before attempting to reconnect to a given host. This avoids repeatedly connecting to a host in a tight loop. This backoff applies to all connection attempts by the client to a broker.

https://kafka.apache.org/documentation/#streamsconfigs_reconnect.backoff.max.ms

The maximum amount of time in milliseconds to wait when reconnecting to a broker that has repeatedly failed to connect. If provided, the backoff per host will increase exponentially for each consecutive connection failure, up to this maximum. After calculating the backoff increase, 20% random jitter is added to avoid connection storms.