Search code examples
scalaapache-kafkaakkaakka-streamreactive-kafka

Equivalent of kafkaConsumer.partitionsFor using reactive kafka (akka kafka streams)


I'm using reactive-kafka (akka kafka streams):

https://doc.akka.io/docs/akka-stream-kafka/current/consumer.html

What is the equivalent of the below code using reactive-kafka?

import org.apache.kafka.clients.consumer.KafkaConsumer
...
val properties = new Properties()
properties.put("bootstrap.servers", "kafka:9092")

val kafkaConsumer = new KafkaConsumer[String, String](properties)
kafkaConsumer.partitionsFor("my-topic")

Solution

  • This is not currently exposed directly in the Reactive Kafka API.

    This is probably because Reactive Kafka focuses on streaming events in a reactive way to/from Akka-Streams based consumers/producers.

    You can still use the official Kafka client to get a consumer to fetch the metadata from a cluster. This does not require additional dependencies, as it is brought in by Reactive Kafka.