title: Unexpected Kafka request of type METADATA during SASL handshake
body: <p>I am trying to connect Kafka Java Client to a Kafka broker using SASL Plain. But when I try to send a message from the Producer, the Kafka Server logs the following error:</p>
  
  <pre><code>[2020-04-30 14:48:14,955] INFO [SocketServer brokerId=0] Failed authentication with /127.0.0.1 (Unexpected Kafka request of type METADATA during SASL handshake.) (org.apache.kafka.common.network.Selector)
  </code></pre>
  
  <p>By the looks, the producer tries to send a metadata request, before the SASL handshake. How can I do the handshake before sending the message?</p>
  
  <p>Following is my <code>kafka_server_jaas.conf</code> file, which is used for Kafka Server.</p>
  
  <pre><code>KafkaServer {
      org.apache.kafka.common.security.plain.PlainLoginModule required
      username="admin"
      password="admin-secret"
      user_admin="admin-secret";
  };
  
  Client {
      org.apache.kafka.common.security.plain.PlainLoginModule required
      username="admin"
      password="admin-secret";
  };
  </code></pre>
  
  <p>Following is my <code>zookeeper_jaas.conf</code> file, which is used for the zookeeper:</p>
  
  <pre><code>Server {
      org.apache.kafka.common.security.plain.PlainLoginModule required
      username="admin"
      password="admin-secret"
      user_admin="admin-secret";
  };
  </code></pre>
  
  <p>In my Java producer, I set the following properties:</p>
  
  <pre class="lang-java prettyprint-override"><code>Properties properties = new Properties();
  properties.put("bootstrap.servers", "localhost:9092");
  properties.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"admin\" password=\"admin_secret\"");
  properties.put("sasl.mechanisms", "PLAIN");
  properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
  KafkaProducer kafkaProducer = new KafkaProducer(properties);
  </code></pre>
  
  <p>Is there anything wrong I am doing?</p>