flink 消费 kafka数据,将结果写入到elasticsearch中

本文介绍了如何在MAC环境下搭建Flink、Kafka和Elasticsearch,并通过Java开发Flink程序从Kafka消费数据,经过处理后写入Elasticsearch。详细步骤包括组件下载、安装、配置、数据生产和消费,以及Flink作业的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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"  查看版本
 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值