当前位置:K88软件开发文章中心大数据Apache Kafka → 文章内容

Apache Kafka 简单生产者示例

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-26 10:04:50

e)) //print the topic name System.out.println("Subscribed to topic " + topicName); int i = 0; while (true) { ConsumerRecords<String, String> records = con-sumer.poll(100); for (ConsumerRecord<String, String> record : records) // print the offset,key and value for the consumer records. System.out.printf("offset = %d, key = %s, value = %s\n", record.offset(), record.key(), record.value()); } }}编译 - 可以使用以下命令编译应用程序。javac -cp “/path/to/kafka/kafka_2.11-0.9.0.0/lib/*" *.java执行 - 可以使用以下命令执行应用程序java -cp “/path/to/kafka/kafka_2.11-0.9.0.0/lib/*":. SimpleConsumer <topic-name>输入 - 打开生成器CLI并向主题发送一些消息。 你可以把smple输入为\'Hello Consumer\'。输出 - 以下是输出。Subscribed to topic Hello-Kafkaoffset = 3, key = null, value = Hello Consumer

上一页  [1] [2] [3] 


Apache Kafka 简单生产者示例