• 大小: 3KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: 其他
  • 标签: kafka  

资源简介

kafka集群测试,生产、消费实例代码,kafka-demo.rar

资源截图

代码片段和文件信息

package cn.slimsmart.kafka.demo;

import java.util.Properties;

import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

public class KafkaProductor {

public static void main(String[] args) throws InterruptedException {
Properties properties = new Properties();
properties.put(“zk.connect“ “192.168.36.127:2181192.168.36.91:2181“);
properties.put(“metadata.broker.list“ “192.168.36.127:9092192.168.36.91:9092192.168.36.91:9092“);
properties.put(“zk.connectiontimeout.ms“ “10000“);
properties.put(“serializer.class“ “kafka.serializer.StringEncoder“);

ProducerConfig producerConfig = new ProducerConfig(properties);
Producer producer = new Producer
producerConfig);

// 构建消息体
KeyedMessage keyedMessage = new KeyedMessage
“test-topic“ “test-message“);
producer.send(keyedMessage);

Thread.sleep(1000);

producer.close();
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        540  2014-11-02 15:44  kafka-demo\pom.xml

     文件       1033  2014-11-02 18:12  kafka-demo\src\main\java\cn\slimsmart\kafka\demo\KafkaProductor.java

     文件       2202  2014-11-02 18:49  kafka-demo\src\test\java\cn\slimsmart\kafka\demo\KafkaConsumer.java

     目录          0  2014-11-02 18:48  kafka-demo\src\main\java\cn\slimsmart\kafka\demo

     目录          0  2014-11-02 18:48  kafka-demo\src\test\java\cn\slimsmart\kafka\demo

     目录          0  2014-11-02 18:48  kafka-demo\src\main\java\cn\slimsmart\kafka

     目录          0  2014-11-02 18:48  kafka-demo\src\test\java\cn\slimsmart\kafka

     目录          0  2014-11-02 18:48  kafka-demo\src\main\java\cn\slimsmart

     目录          0  2014-11-02 18:48  kafka-demo\src\test\java\cn\slimsmart

     目录          0  2014-11-02 18:48  kafka-demo\src\main\java\cn

     目录          0  2014-11-02 18:48  kafka-demo\src\test\java\cn

     目录          0  2014-11-02 18:48  kafka-demo\src\main\java

     目录          0  2014-11-02 18:47  kafka-demo\src\main\resources

     目录          0  2014-11-02 18:48  kafka-demo\src\test\java

     目录          0  2014-11-02 18:47  kafka-demo\src\test\resources

     目录          0  2014-11-02 18:48  kafka-demo\src\main

     目录          0  2014-11-02 18:48  kafka-demo\src\test

     目录          0  2014-11-02 18:48  kafka-demo\src

     目录          0  2014-11-02 18:48  kafka-demo

----------- ---------  ---------- -----  ----

                 3775                    19


评论

共有 条评论