How to use alpakka kafka connection-checker?
This topic is based on a conversation between an anonymous user of Akka and our “Ask AI about Akka” bot in the documentation.
How to use alpakka kafka connection-checker?
This topic is based on a conversation between an anonymous user of Akka and our “Ask AI about Akka” bot in the documentation.
The connection-checker
is a feature in Alpakka Kafka consumer settings that checks the connection to the Kafka broker. It uses listTopics
requests with the timeout configured by consumer.metadata-request-timeout
.
Here is an example of how to configure it:
connection-checker {
#Flag to turn on connection checker
enable = false
# Amount of attempts to be performed after a first connection failure occurs
# Required, non-negative integer
max-retries = 3
# Interval for the connection check. Used as the base for exponential retry.
check-interval = 15s
# Check interval multiplier for backoff interval
# Required, positive number
backoff-factor = 2.0
}
In this configuration:
enable
is a flag to turn on the connection checker.check-interval
is the interval for the connection check. It is used as the base for exponential retry.backoff-factor
is the check interval multiplier for the backoff interval.Please note that you need to set enable = true to activate the connection checker.
You can find more details in the Alpakka Kafka documentation.
What happen if its enabled and 3 retries occur with no connection?
In that case, the stream gets cancelled. Please have a look at the “Error handling” part of the Alpakka Kafka documentation.
If the connection-checker
is enabled and the maximum number of retries (in this case, 3) is reached without a successful connection, the Alpakka Kafka consumer will not be able to connect to the Kafka broker.
The connection-checker
will stop attempting to connect after the maximum number of retries is reached. This means that if the Kafka broker becomes available after this point, the consumer will not automatically reconnect.
It’s important to handle these situations in your application logic, possibly by implementing a reconnection strategy or alerting the system administrator.
Can I log those retries?
Yes, retries are logged at DEBUG
level when you enable LoggingReceive
as follows:
akka {
actor {
debug {
receive = on
}
}
}
Successful attempts are logged annotated with with the word regular
and failed attempts are logged with the annotation backoff(failedAttempts, backoffCheckInterval)
within the log message.
Please have a look at the LoggingReceive
decorator documentation here: Classic Logging • Akka Documentation.