Kafka API实战
第4章 KafkaAPI实战
1)启动zk和kafka集群,在kafka集群中打开一个消费者
[hadoop102 kafka]$ bin/kafka-console-consumer.sh \ --zookeeper hadoop01:2181 --topic first
2)导入pom依赖
<dependencies> <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients --> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.2.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka --> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka_2.12</artifactId> <version>2.2.1</version> </dependency> </dependencies>
4.2 Kafka生产者Java API
4.2.1 创建生产者(过时的API)