spring-cloud / spring-cloud-stream-binder-kafka

Spring Cloud Stream binders for Apache Kafka and Kafka Streams
Apache License 2.0
331 stars 302 forks source link

AdminClient / KafkaAdmin with merged standard kafka and binder properties #1178

Closed skomarica closed 2 years ago

skomarica commented 2 years ago

Hi,

First of all, my apologies if this was already answered elsewhere; I reviewed the docs, SO Q&A and previous similar issues, but couldn't find the answer.

We use Kafka binder for our spring boot / cloud based services. The complete configuration is based on spring.cloud.stream.* properties and everything has been working as expected so far.

Now, I want to use the AdminClient to verify certain things on the cluster (e.g. list/describe topics). I tried using an autowired KafkaAdmin bean to provide the configuration properties, like:

        try (final AdminClient adminClient = AdminClient.create(kafkaAdmin.getConfigurationProperties())) {

, but these configuration properties don't seem to pick up any of the binder properties (e.g. spring.cloud.stream.kafka.binder.brokers, spring.cloud.stream.kafka.binder.configuration.*...). I also looked at the KafkaAdmin bean implementation and configuration, and it doesn't look like the class is supposed to do any kind of properties merging. If this is the case, it makes the auto-configured KafkaAdmin bean a bit pointless.

I see that the internal AdminClient used by KafkaTopicProvisioner gets initialised correctly, but there is a custom internal logic in the constructor of that class, normalising and merging the standard kafka properties with the kafka binder ones. Most of these classes and beans are internal / package private, and we can't easily use them.

The question is - is there a suggested way to create an AdminClient that will be correctly initialised, respecting all the spring.cloud.stream.kafka.binder.* properties?

garyrussell commented 2 years ago

This is currently not supported; the auto-configured (by Boot) KafkaAdmin only uses the Boot properties.

Perhaps the KafkaTopicProvisioner could be modified to provide an API to retrieve the merged admin properties for each binding.

sobychacko commented 2 years ago

Issue moved to spring-cloud/spring-cloud-stream #2322 via ZenHub