# How to use alpakka kafka connection-checker?

**URL:** <https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857>\
**Category:** Akka Libraries\
**Created:** [August 1, 2024, 11:19am UTC](https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857 "2024-08-01T11:19:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnonymousUser](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@AnonymousUser](https://discuss.akka.io/u/AnonymousUser)\
**Post date:** [August 1, 2024, 11:19am UTC](https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857/1 "2024-08-01T11:19:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ask-AI-Bot](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Ask-AI-Bot](https://discuss.akka.io/u/Ask-AI-Bot)\
**Post date:** [August 1, 2024, 11:21am UTC](https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857/2 "2024-08-01T11:21:36Z")

</div>

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:

```auto
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.
- `max-retries`` is the number of attempts to be performed after a first connection failure occurs.
- `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](https://doc.akka.io/docs/alpakka-kafka/current/consumer.html#settings).

---

<div class="post-metadata">

**Author:** ![AnonymousUser](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@AnonymousUser](https://discuss.akka.io/u/AnonymousUser)\
**Post date:** [August 1, 2024, 11:21am UTC](https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857/3 "2024-08-01T11:21:55Z")

</div>

What happen if its enabled and 3 retries occur with no connection?

---

<div class="post-metadata">

**Author:** ![Ask-AI-Bot](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Ask-AI-Bot](https://discuss.akka.io/u/Ask-AI-Bot)\
**Post date:** [August 1, 2024, 11:38am UTC](https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857/4 "2024-08-01T11:38:31Z")

</div>

In that case, the stream gets cancelled. Please have a look at the “Error handling” part of the Alpakka Kafka [documentation](https://doc.akka.io/docs/alpakka-kafka/current/errorhandling.html#restarting-the-stream-with-a-backoff-stage).

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.

---

<div class="post-metadata">

**Author:** ![AnonymousUser](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@AnonymousUser](https://discuss.akka.io/u/AnonymousUser)\
**Post date:** [August 1, 2024, 11:38am UTC](https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857/5 "2024-08-01T11:38:42Z")

</div>

Can I log those retries?

---

<div class="post-metadata">

**Author:** ![Ask-AI-Bot](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Ask-AI-Bot](https://discuss.akka.io/u/Ask-AI-Bot)\
**Post date:** [August 1, 2024, 11:41am UTC](https://discuss.akka.io/t/how-to-use-alpakka-kafka-connection-checker/10857/6 "2024-08-01T11:41:46Z")

</div>

Yes, retries are logged at `DEBUG` level when you enable `LoggingReceive` as follows:

```auto
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](https://doc.akka.io/docs/akka/current/logging.html#auxiliary-logging-options).
