kafka环境搭建及librdkafka测试

(2016-04-05 10:18:25)

 
一、kafka环境搭建(转自http://kafka.apache.org/documentation.html#gettingStarted)

Step 1: Download the code

Download the 0.9.0.0 release and un-tar it.

tar -xzf kafka_2.11-0.9.0.0.tgz > cd kafka_2.11-0.9.0.0

Step 2: Start the server

Kafka uses ZooKeeper so you need to first start a ZooKeeper server if you don't already have one. You can use the convenience script packaged with kafka to get a quick-and-dirty single-node ZooKeeper instance.

bin/zookeeper-server-start.sh config/zookeeper.properties [2013-04-22 15:01:37,495] INFO Reading configuration from:config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig) ...

Now start the Kafka server:

bin/kafka-server-start.sh config/server.properties [2013-04-22 15:01:47,028] INFO Verifying properties (kafka.utils.VerifiableProperties) [2013-04-22 15:01:47,051] INFO Property socket.send.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties) ...

Step 3: Create a topic

Let's create a topic named "test" with a single partition and only one replica:

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

We can now see that topic if we run the list topic command:

bin/kafka-topics.sh --list --zookeeper localhost:2181 test

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 4: Send some messages

Kafka comes with a command line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. By default each line will be sent as a separate message.

Run the producer and then type a few messages into the console to send to the server.

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test This is a message This is another message

Step 5: Start a consumer

Kafka also has a command line consumer that will dump out messages to standard output.

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning This is a message This is another message

If you have each of the above commands running in a different terminal then you should now be able to type messages into the producer terminal and see them appear in the consumer terminal.

All of the command line tools have additional options; running the command with no arguments will display usage information documenting them in more detail.

二、kafka环境配置(若省略此步,其他主机上的客户端访问时会报错)

修改 conf/server.properties
 
zookeeper.connect=192.168.197.170:2181,192.168.197.171:2181,192.168.197.172:2181(换成你自己的IP)
 
broker.id分别改成
broker.id=170
broker.id=171
broker.id=172
host.name分别改成(如果不改,client访问集群时,如果没在hosts配置对应机器的 hostname,访问将会报错)
host.name=192.168.197.170(换成你自己的IP)
host.name=192.168.197.171
host.name=192.168.197.172
可根据需求修改

port: broker节点使用端口号 默认 9092
log.dir: 消息目录位置

3,执行librdkafka的例程

修改kafka的配置文件后再重启kafka服务以及消费者程序

此时在客户端主机执行

examples/rdkafka_example -P -b 128.1.0.149:9092 -t test    (128.1.0.149换成你自己的IP)

后,会在服务端的消费者执行窗口看到客户端你输入的字符

对于初学者可能参数都不知道该怎么加,可以通过三个地方学习

a,第一步中的kafka生产者测试实例,

b,第三步中的librdkafka生产者实例,

c,执行rdkafka_example时不加参数会提示帮助。

最重要的一点还是要了解kafka的框架。

kafka环境搭建及librdkafka测试的更多相关文章

  1. kafka环境搭建

    kafka环境搭建 for mac 对应qq群号:616961231 在之前的文章中, 有学习能力和兴趣爱好的同学,自己动手维护测试环境,丰衣足食是最好的办法,今天我们来讲讲kafka在mac上的安装 ...

  2. windows下golang实现Kfaka消息发送及kafka环境搭建

    kafka环境搭建: 一.安装配置java-jdk (1)kafka需要java环境,安装java-jdk,下载地址:https://www.oracle.com/technetwork/java/j ...

  3. windows kafka 环境搭建踩坑记

    版本介绍(64位): Windows 10 JDK1.8.0_171 zookeeper-3.4.8/ kafka_2.11-0.10.0.1.tgz 点击链接进行下载 1. JDK安装和环境搭建 自 ...

  4. 【入门教程】kafka环境搭建以及基础教程

    问题导读 1.Kafka独特设计在什么地方?2.Kafka如何搭建及创建topic.发送消息.消费消息?3.如何书写Kafka程序?4.数据传输的事务定义有哪三种?5.Kafka判断一个节点是否活着有 ...

  5. Kafka - 环境搭建

    一.概述 Kafka(官网地址)专为分布式高吞吐量系统而设计. Kafka往往工作得很好,作为一个更传统的消息代理的替代品. 与其他消息传递系统相比,Kafka具有更好的吞吐量,内置分区,复制和固有的 ...

  6. kafka环境搭建和使用(python API)

    引言 上一篇文章了解了kafka的重要组件zookeeper,用来保存broker.consumer等相关信息,做到平滑扩展.这篇文章就实际操作部署下kafka,用几个简单的例子加深对kafka的理解 ...

  7. windows环境下mosquitto环境搭建与mqtt测试

    https://blog.csdn.net/pgpanda/article/details/51800865 工作需求,自己在windows下搭建了一个mosquitto环境测试mqtt 话不多说,直 ...

  8. 转:(WIN)S04-CH01 PCIE XDMA开发环境搭建以及环路测试

    摘要: 这一章开始主要介绍 XILINX FPGA PICE IP XDMA IP的使用.XDMA IP使用部分教程分LINUX 篇和WINDOWS篇两个部分.通过实战,面向应用,提供给大家 XILI ...

  9. Redis环境搭建和代码测试及与GIS结合的GEO数据类型预研

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 1.1传统MySQL+ Memcached架构遇到的问题 My ...

随机推荐

  1. C++强制类型转换操作符 dynamic_cast

    dynamic_cast是四个强制类型转换操作符中最特殊的一个,它支持运行时识别指针或引用. >>>>>>>>>>>编译器的RTTI设 ...

  2. linux命令语法格式

    一.命令的一般格式 command [option]... [argument]... command [options] [arguments] 具体说明: 1.command: 表示命令的名称,如 ...

  3. matlab实现hog特征

    %%matlab实现hog特征 %修改自http://www.cnblogs.com/tiandsp/archive/2013/05/24/3097503.html %input: img %outp ...

  4. Android成长日记-ContextMenu实现上下文菜单

    一. ContextMenu的组成 标题以及标题图标 菜单内容 菜单内容的点击事件 二. ContextMenu与OptionMenu的区别 OptionMenu对应的是activity,一个acti ...

  5. Andirod——网络连接(HttpURLConnection)

    Android中使用HTTP协议访问网络的方法主要分为两种: 使用HttpURLConnection 使用HttpClient 本文主要内容是HttpURLConnection的使用. HttpURL ...

  6. RabbitMQ 通过记日志来看routingkey

    RoutingKey 每个项目都需要记录日志,日志则一般会分为多种级别,常见的是 Info.debug.warn.Error 对于前三种日志,在项目运行中会产生大量的消息,但是一般多数情况下是不会用到 ...

  7. 随便聊聊 SOA & SOAP & WebService 的一些东西,以及客户端开发的代码逻辑解析

    http://blog.csdn.net/hikaliv/article/details/6459779 一天的时间调通了一个 WebService 的 Java 端的 C/S.一个 Android  ...

  8. java编程思想-java中的并发(二)

    二.共享受限资源 有了并发就可以同时做多件事情了.但是,两个或多个线程彼此互相干涉的问题也就出现了.如果不防范这种冲突,就可能发生两个线程同时试图访问同一个银行账户,或向同一个打印机打印,改变同一个值 ...

  9. select例子

    好长时间没有写了,其实一直在坚持学习. #include <sys/types.h> #include <sys/socket.h> #include <stdio.h& ...

  10. Distinct

    SELECT 指令让我们能够读取表格中一个或数个栏位的所有资料.这将把所有的资料都抓出,无论资料值有无重复.在资料处理中,我们会经常碰到需要找出表格内的不同资料值的情况.换句话说,我们需要知道这个表格 ...