Skip to content
Advertisement

How to use ${akka.kafka.consumer}?

I’m attempting to use the default Kafka config settings but I’m unsure how ${akka.kafka.consumer} is set. Reading https://doc.akka.io/docs/alpakka-kafka/current/consumer.html#config-inheritance Ive defined the following :

In application.conf I define :

our-kafka-consumer: ${akka.kafka.consumer} {
  kafka-clients {
    bootstrap.servers = "kafka-host:9092"
  }
}

But receive error when I startup the Akka Cluster:

Could not resolve substitution to a value: ${akka.kafka.consumer}

Is ${akka.kafka.consumer} an environment variable that I need to set externally when starting the Akka Cluster or is ${akka.kafka.consumer} a config variable that already exists ?

The point is to use ${akka.kafka.consumer} and then overwrite the defaults as required ?

Advertisement

Answer

As you’ve noticed, the section of the docs is “config inheritance”. It is showing how you can define your normal configuration in one section and then extend/replace that configuration in another section. The sample they show has a akka { kafka.consumer } section at the top (click the “source” button the example to see this section). And then, because of the naming and inheritance features of HOCON, can just inherit from that section using ${akka.kafka.consumer}. There’s no need to actually use that inheritance to configure Alpakka, that is just a best practice. If you are just trying to use the default config, it’s, well, already the default.

For example, if you are just trying to define the bootstrap server, you don’t have to use inheritance to do that as they do in that example. You can just specify akka.kafka.consumer.kafka-clients.bootstrap.servers = "yourbootstrap:9092" directly. The inheritance is just so that you can specify the shared settings in one place.

If you are just trying to learn how to configure Alpakka, look at the section immediately above this on Settings. I find it most helpful to look at the reference config, which you can see by clicking on the reference.conf tab next to “Important consumer settings”.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement