spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.15k stars 40.68k forks source link

As a spring kafka user i want to set clusterid filed through yml properties so that Spring Kafka Observation works seemlessly #42028

Closed iamgollapalli closed 2 months ago

iamgollapalli commented 2 months ago

How to work with Spring Kafka Observation without clusterId ?

Problem: while using spring Kafka observation, KafkaTemplate and KafkaMessageListenerContainer creates KafkaRecordSenderContext & KafkaRecordReceiverContext objects with clusterid derived from KafkaAdmin

But depending on the environment KafkaAdmin may not work expected for example in AWS MSK, we need to have describe cluster permission to fetch the cluster id details and even fetching cluster id value with KafkaAdmin#Describecluster is time consuming process. It will be even bigger issue if for each message application tries to fetch clusterid (say for example no access to describe cluster).

Some times due to repetitive process of fetching cluster id we are observing memory issue and Consumer Lag.

It will be better similar to other properties that user can set the clusterid under prefix spring.kafka.admin, fetch clusterid value only if the the corresponding field is not set in yml properties.

philwebb commented 2 months ago

It looks like we could call KafkaAdmin.setClusterId(...) in KafkaAutoConfiguration to do this. In the meantime, you could probably write a BeanPostProcessor to call this method yourself.

wilkinsona commented 2 months ago

Duplicates #38825.