Search code examples
apache-kafkasasl

Unexpected Kafka request of type METADATA during SASL handshake when connecting to kafka server by a consumer


I have 'kafka_2.13-3.7.0' on Windows 11

I want to run the kafka with SASL_PLAINTEXT, I followed the steps in https://kafka.apache.org/documentation/#security_sasl_plain

I added the following setting in file server.properties

listeners=SASL_PLAINTEXT://localhost:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN

I defined a config file 'kafka_jaas.conf' containing the following content

KafkaServer {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="admin"
    password="admin-secret"
    user_admin="admin-secret"
    user_alice="alice-secret";
};

Then I started the kafka server with the following JVM, the server started up successfully

-Djava.security.auth.login.config=kafka_jaas.conf

Then I added the following content in the consumer.properties

sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="alice"   password="alice-secret";  
security.protocol=SASL_PLAINTEXT  
sasl.mechanism=PLAIN

Finally I ran a consumer kafka-console-consumer.bat --topic my-topic --from-beginning --bootstrap-server localhost:9092

But I got the following error [2024-06-01 23:51:57,041] INFO [SocketServer listenerType=ZK_BROKER, nodeId=0] Failed authentication with /127.0.0.1 (channelId=127.0.0.1:9092-127.0.0.1:56526-5) (Unexpected Kafka request of type METADATA during SASL handshake.) (org.apache.kafka.common.network.Selector)

Could anyone help me out, thank you.

I hope the kafka consumer started up successfully.


Solution

  • The consumer.properties file must be provided by --consumer.config for the console consumer