AdminClient provides useful admin operations over kafka. Consider adding as part of kafka auto-configuration beans.
-
One can argue that this functionality need to be wrapped by KafkaAdmin
-
created as part discussion 11435 pull request discussion
Comment From: snicoll
paging @garyrussell to get more feedback on this.
Comment From: garyrussell
A KafkaAdmin @Bean is already autoconfigured.
Comment From: garyrussell
If an application needs access to an AdminClient directly, e.g. to use features not exposed by the KafkaAdmin, it can use AdminClient.create(kafkaAdmin.getConfig()).
But I don't have a strong objection to adding the bean if it's felt necessary.
Comment From: snicoll
Unless this is really necessary, I'd rather avoid exposing it. @Jcamilorada perhaps you could rework your original PR with that suggestion?
Comment From: garyrussell
I looked at the health indicator PR.
One benefit of it being a @Bean is that it implements AutoCloseable, so Spring will close the connection, when the context is close()d, if an application forgets to do so.
With my suggestion above, the app is responsible for doing his own close.
On the other hand, I wonder if we really should keep open a long-lived admin connection for health checks; perhaps it would be better to use a new AdminClient each time (and close the resources).
Comment From: Jcamilorada
@garyrussell @snicoll thanks, I am going to update pull request to use new AdminClient each time, probably test will require KafkaEmbedded as well.
Comment From: snicoll
Alright, thanks both!
Comment From: massivespace
I'm trying to access the admin client's topic list for actuator health endpoint, but the suggestion above to use AdminClient.create(kafkaAdmin.getConfig()) does not work for me.
I'm using kotlin with spring boot, so it's a bit different: AdminClient.create(kafkaAdmin?.configurationProperties), but the list of configuration properties is only a single item, a default boostrap server to localhost. Is there an obvious way to get a KafkaAdmin that has been configured via the properties file (bootstrap and security settings)?
Comment From: garyrussell
Don't ask questions on old, closed, issues; use Stack Overflow to ask questions.
The auto configured KafkaAdmin has all the common and admin properties.
i.e. spring.kafka.*, excluding spring.kafka.consumer.* and spring.kafka.producer.* and spring-kafka-streams.*, and including spring.kafka.admin.* properties.
https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.kafka.admin.client-id
If you are seeing something different ask a question on stack overflow showing code and configuration.
However, the admin properties are not involved with creating topics, only configuring the admin, to enable it to create those topics.
The auto-created topics are beans in the application context of type NewTopic or NewTopics.
Comment From: massivespace
For the benefit of others, I am using spring cloud kafka binder (which appears to be the recommended approach by spring boot), not spring-kafka directly. The documentation for the kafka binders is out of date in several locations, so maybe I found the wrong configurations, but after multiple tries, I ended up with working properties for brokers at: spring.cloud.stream.kafka.binder.brokers.
Moving this to spring.kafka.bootstrap-servers allows me to utilize the configuration properties mentioned above.
Comment From: garyrussell
There is an open issue against SCSt for this https://github.com/spring-cloud/spring-cloud-stream/issues/2673