flink 消费 kafka数据,将结果写入到elasticsearch中
开发工具:IDEA、JDK1.8
本地开发组件:Kafka、Flink、ElasticSearch
各组件在mac上过程如下:
1. 本地安装下载 kafka_2.12-2.2.0
下载kafka:https://kafka.apache.org/quickstart#quickstart_download
本地模式使用kafka的zookeeper服务,不用另外安装。
启动zk + kafka:
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
创建topic
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test-cash
命令行生产数据
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test-cash
查看topic的数据
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-cash --from-beginning
删除topic
bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic test-cash
2. 本地安装flink & Elasticsearch
下载flink-1.7.2
https://flink.apache.org/downloads.html#apache-flink-172
进入目录,运行 & 关闭flink
./bin/start-cluster.sh
./bin/stop-cluster.sh
下载 Elasticsearch5.6
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.16.tar.gz
本地运行 ./bin/elasticsearch
curl -XPUT "http://localhost:9200/myindex-idx" 创建索引,名称为 myindex
创建mapping,名称为 name_count
curl -XPUT "http://localhost:9200/myindex-idx/_mapping/name_count" -d'{"name_count":{"dynamic":"strict","properties":{"name":{"type":"keyword"},"count":{"type":"long"},"time":{"type":"long"}}}'
curl -XGET "http://localhost:9200" 查看版本