二、修改hosts文件
192.168.16.14 hdp-1
三、根据自己的kafka版本引入依赖
<!-- 需要引入与所安装的kafka对应版本的依赖 -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>3.1.0</version>
</dependency>
四、生产者样例代码
package com.example.demo.kafka;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
/**
* @Author: meng
* @Version: 1.0
*/
public class ProductKafkaKerberos {
public static void main(String[] args) {
String filePath = System.getProperty("user.dir") + "\\conf\\";
System.setProperty("java.security.auth.login.config", filePath + "kafka_client_jaas.conf");
System.setProperty("java.security.krb5.conf", filePath + "krb5.conf");
Properties props = new Properties();
props.put("bootstrap.servers", "hdp-1:9092");
props.put("acks", "all");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
// sas