spring-cloud-stream icon indicating copy to clipboard operation
spring-cloud-stream copied to clipboard

Force disable the creation of Kafka Admin Client

Open akoufa opened this issue 11 months ago • 3 comments

I am using Spring Cloud Stream Binder Kafka to connect to an Azure Event Hub Kafka. I am observing a strange behaviour that Kafka AdminClient is being created despite being disabled by the auto topic creation property. Is there a workaround to force disable the Kafka Admin Client creation?

My configuration looks like this:

spring:
  cloud:
    azure:
      eventhubs:
        connection-string: ${azure.eventhub.connection-string}
    stream:
      kafka:
        binder:
          autoCreateTopics: false
          brokers: ${azure.eventhub.namespace}
          configuration:
            security.protocol: SASL_SSL
            sasl.mechanism: PLAIN
            sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="${azure.eventhub.connection-string}";
          consumer-properties:
            heartbeat.interval.ms: 3000
            session.timeout.ms: 30000
            max.poll.interval.ms: 300000

akoufa avatar Mar 06 '24 10:03 akoufa

Disabling autoCreateTopic will not prevent AdminClient to be created as the binder needs the admin to perform other broker related tasks. At the moment, you cannot control that behavior in the binder. What is the use case to not have the AdminClient created?

sobychacko avatar Mar 06 '24 14:03 sobychacko

@sobychacko What are the broker related tasks that are needed for a consuming only application?

akoufa avatar Mar 07 '24 08:03 akoufa

When the binder establishes the consumer binding, there is an unconditional call to the broker to get the partitions to listen from. For that, we use the AdminClient. See here: https://github.com/spring-cloud/spring-cloud-stream/blob/main/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/provisioning/KafkaTopicProvisioner.java#L641

This is triggered from here: https://github.com/spring-cloud/spring-cloud-stream/blob/main/binders/kafka-binder/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaMessageChannelBinder.java#L613

sobychacko avatar Mar 08 '24 19:03 sobychacko