Openresty集成kafka客户端
1、参考网站 https://github.com/xiaoenai/lua-resty-kafka
2、说明:lua-resty-kafka是Openresty集成kafka的一个客户端
一、lua-resty-kafka集成到Openresty
1、下载
https://github.com/xiaoenai/lua-resty-kafka到本地
2、复制kafka目录
3、打开Openresty的如下目录粘贴kafka
二、kafka客户端使用
1、打开bnc项目
新建kafka_init_client.lua文件
2、编写脚本(例子)
三、启动验证
1、kafka集群
(1)10.221.164.116、10.221.164.120、10.221.164.121
(2)打开上述任意一个服务器例如10.221.164.116
进入cd /usr/local/kafka_2.11-2.0.0/ 目录
2、kafka创建topic
在/usr/local/kafka_2.11-2.0.0/ 执行命令
bin/kafka-topics.sh --create --zookeeper 10.221.164.116:2181 --replication-factor 1 --partitions 1 --topic test2
其中test2为主题名称
3、查询所有topic
在/usr/local/kafka_2.11-2.0.0/ 执行命令
bin/kafka-topics.sh --zookeeper 10.221.164.116:2181 --list
4、启动消费者
在/usr/local/kafka_2.11-2.0.0/ 执行命令
bin/kafka-console-consumer.sh --bootstrap-server 10.221.164.116:9092 --topic testtopic --from-beginning
可以看到消费者进程一直处于监听
5、启动bnc进行验证
浏览器访问:http://localhost:8088/kafkamq
浏览器结果页
服务器结果