1

Currently I'm using Spring boot 2.4.0 with spring-kafka.

I want to use consumers and producers but not kafka admin.

I tried to override KafkaAdmin class by settings "bootstrap.servers" to null, but doesn't work. It still 'try' to connect to make KafkaAdmin and log errors. It's not fatal, but is there any way to totally disable kafka admin?

Roeniss
  • 386
  • 5
  • 16

1 Answers1

6

Your concern does not make sense. The KafkaAdmin does not connect by itself. The logic there is like this:

public final boolean initialize() {
        Collection<NewTopic> newTopics = this.applicationContext.getBeansOfType(NewTopic.class, false, false).values();
        if (newTopics.size() > 0) {
            AdminClient adminClient = null;
            try {
                Map<String, Object> configs2 = new HashMap<>(this.configs);
                checkBootstrap(configs2);
                adminClient = AdminClient.create(configs2);
            }
            catch (Exception e) {
                if (!this.initializingContext || this.fatalIfBrokerNotAvailable) {
                    throw new IllegalStateException("Could not create admin", e);
                }
                else {
                    LOGGER.error(e, "Could not create admin");
                }
            }

So, if there is no any NewTopic beans in the application context the KafkaAdmin does nothing. If you have some, then what is the reason for that, if not create new topics on the broker before producing/consuming. Therefore KafkaAdmin logic.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118