一、生产者配置参数代码实现
### --- 创建maven项目:demo-04-kafka-properties
~~~ 配置pom.xml文件;导入依赖
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
### --- 编程代码实现
package com.yanqi.kafka.demo.producer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import java.util.HashMap;
import java.util.Map;
public class MyProducer {
public static void main(String[] args) {
Map<String, Object> configs = new HashMap<>();
// bootstrap.servers
configs.put("bootstrap.servers", "node1:9092");
configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "node1:9092");
KafkaProducer<String, String> producer = new KafkaProducer<String, String>(configs);
}
}