基于Kafka的高性能流處理平臺——Confluent


軟件準(zhǔn)備

  • Confluent安裝包
    下載地址:https://www.confluent.io/download/
    Confluent有兩個類型可以下載,企業(yè)版(Enterprise)需要付費悦穿,可以免費使用30天告抄,我這里使用的是開源版(Open Source)版钝诚,版本號是4.1.1

1. Confluent 介紹

(1) Confluent 是什么隘截?

Confluent平臺是一個可靠的铲咨,高性能的流處理平臺固歪,你可以通過這個平臺組織和管理各式各樣的數(shù)據(jù)源中的數(shù)據(jù)。

image.png

(2) Confluent 中有什么胯努?

  • Confluent開源版
    • Confluent Kafka Connectors
      • Kafka Connect JDBC Connector
      • Kafka Connect HDFS Connector
      • Kafka Connect Elasticsearch Connector
      • Kafka Connect S3 Connector
    • Confluent Kafka Clients
      • C/C++ Client Library
      • Python Client Library
      • Go Client Library
      • .Net Client Library
    • Confluent Schema Registry
    • Confluent Kafka REST Proxy
  • Confluent 企業(yè)版中增加的功能
    • Automatic Data Balancing
    • Multi-Datacenter Replication
    • Confluent Control Center
    • JMS Client

2. Confluent 開源版安裝

(1) 解壓安裝包牢裳,可以看到以下目錄:

[root@confluent confluent-4.1.1]# ll
total 24
drwxr-xr-x  3 1000 1000 4096 May 12 08:01 bin
drwxr-xr-x 14 1000 1000 4096 May 12 07:05 etc
drwxr-xr-x  3 1000 1000 4096 May 12 06:47 lib
-rw-r--r--  1 1000 1000  871 May 12 08:02 README
drwxr-xr-x  6 1000 1000 4096 May 12 07:05 share
drwxr-xr-x  2 1000 1000 4096 May 12 08:02 src

(2) 啟動confluent

[root@confluent confluent-4.1.1]# bin/confluent start
Using CONFLUENT_CURRENT: /tmp/confluent.I5Y1nzpT
Starting zookeeper
zookeeper is [UP]
Starting kafka
kafka is [UP]
Starting schema-registry
schema-registry is [UP]
Starting kafka-rest
kafka-rest is [UP]
Starting connect
connect is [UP]
Starting ksql-server
ksql-server is [UP]

confluent start 會啟動 confluent 全部組件,如果想要單獨啟動叶沛,比如單獨啟動 schema-registry蒲讯,可以執(zhí)行以下命令:

schema-registry-start

具體的單獨啟動各組件的命令,進(jìn)入 bin 目錄下灰署,一看就能明白判帮,不再贅述。

3. 簡單使用

(1) 創(chuàng)建 topic

[root@confluent confluent-4.1.1]# bin/kafka-topics \
> --create \
> --zookeeper localhost:2181 \
> --replication-factor 1 \
> --partitions 1 \
> --topic confluent-test-001
Created topic "confluent-test-001".

說明:
confluent 中內(nèi)嵌了 Kafka 和 Zookeeper溉箕,你也可以通過指定不同的 zookeeper 在其他的 kafka 集群中創(chuàng)建 topic 或執(zhí)行其他操作晦墙。

(2) 生產(chǎn)數(shù)據(jù)

[root@confluent confluent-4.1.1]# bin/ksql-datagen \
> quickstart=users \
> format=json \
> topic=confluent-test-001 \
> maxInterval=1000
[2018-06-22 14:53:19,170] INFO AvroDataConfig values: 
    schemas.cache.config = 1
    enhanced.avro.schema.support = false
    connect.meta.data = true
 (io.confluent.connect.avro.AvroDataConfig:179)
User_5 --> ([ 1513083004885 | 'User_5' | 'Region_9' | 'OTHER' ])
User_8 --> ([ 1508770926089 | 'User_8' | 'Region_3' | 'OTHER' ])
User_9 --> ([ 1504006562725 | 'User_9' | 'Region_5' | 'FEMALE' ])
User_8 --> ([ 1490524175099 | 'User_8' | 'Region_2' | 'OTHER' ])
User_8 --> ([ 1489424770134 | 'User_8' | 'Region_8' | 'MALE' ])
User_1 --> ([ 1516449943408 | 'User_1' | 'Region_4' | 'OTHER' ])
......

以上命令是內(nèi)嵌的一個kafka-producer腳本,生成隨機(jī)的用戶信息肴茄,可以通過 quickstart=[CLICKSTREAM_CODES, CLICKSTREAM, CLICKSTREAM_USERS, ORDERS, RATINGS, USERS, USERS_, PAGEVIEWS] 來生成不同的數(shù)據(jù)晌畅,這個腳本會運行很長時間(官網(wǎng)只說了很長時間,到底多長寡痰,沒說)抗楔,除非你手動停止

(3) 使用 KSQL 查詢生產(chǎn)的數(shù)據(jù)

在另一個窗口中棋凳,進(jìn)入KSQL命令行(上一個窗口繼續(xù)發(fā)數(shù)據(jù)不要停)

[root@confluent confluent-4.1.1]# bin/ksql
                  
                  ===========================================
                  =        _  __ _____  ____  _             =
                  =       | |/ // ____|/ __ \| |            =
                  =       | ' /| (___ | |  | | |            =
                  =       |  <  \___ \| |  | | |            =
                  =       | . \ ____) | |__| | |____        =
                  =       |_|\_\_____/ \___\_\______|       =
                  =                                         =
                  =  Streaming SQL Engine for Apache Kafka? =
                  ===========================================

Copyright 2017 Confluent Inc.

CLI v4.1.1, Server v4.1.1 located at http://localhost:8088

Having trouble? Type 'help' (case-insensitive) for a rundown of how things work!

ksql> 

把生產(chǎn)過來的數(shù)據(jù)創(chuàng)建為user表:

ksql> CREATE TABLE users (registertime BIGINT, gender VARCHAR, regionid VARCHAR, \
> userid VARCHAR, \interests array<VARCHAR>, contact_info map<VARCHAR, VARCHAR>) \
> WITH (KAFKA_TOPIC='confluent-test-001', VALUE_FORMAT='JSON', KEY = 'userid');

 Message       
---------------
 Table created 
---------------

設(shè)置消費偏移量為 "earliest":

ksql> SET 'auto.offset.reset'='earliest';
Successfully changed local property 'auto.offset.reset' from 'null' to 'earliest'

查詢:

ksql> select * from users;
1529651156298 | User_7 | 1497590434653 | OTHER | Region_7 | User_7 | null | null
1529651158082 | User_9 | 1508375625042 | OTHER | Region_1 | User_9 | null | null
1529651160496 | User_5 | 1501045879443 | MALE | Region_6 | User_5 | null | null
1529651161870 | User_6 | 1514541057484 | FEMALE | Region_5 | User_6 | null | null
1529651162248 | User_3 | 1498247501220 | MALE | Region_1 | User_3 | null | null
1529651162727 | User_1 | 1495368101769 | FEMALE | Region_3 | User_1 | null | null
1529651164048 | User_4 | 1508110530233 | MALE | Region_6 | User_4 | null | null
.....
# 只要生產(chǎn)數(shù)據(jù)的程序沒有停止,這里會一直打印查詢結(jié)果

4. 關(guān)閉服務(wù)

[root@confluent confluent-4.1.1]# bin/confluent stop
Using CONFLUENT_CURRENT: /tmp/confluent.I5Y1nzpT
Stopping ksql-server
ksql-server is [DOWN]
Stopping connect
connect is [DOWN]
Stopping kafka-rest
kafka-rest is [DOWN]
Stopping schema-registry
schema-registry is [DOWN]
Stopping kafka
kafka is [DOWN]
Stopping zookeeper
zookeeper is [DOWN]
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末连躏,一起剝皮案震驚了整個濱河市剩岳,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌入热,老刑警劉巖拍棕,帶你破解...
    沈念sama閱讀 219,366評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異才顿,居然都是意外死亡莫湘,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評論 3 395
  • 文/潘曉璐 我一進(jìn)店門郑气,熙熙樓的掌柜王于貴愁眉苦臉地迎上來幅垮,“玉大人,你說我怎么就攤上這事尾组∶γⅲ” “怎么了?”我有些...
    開封第一講書人閱讀 165,689評論 0 356
  • 文/不壞的土叔 我叫張陵讳侨,是天一觀的道長呵萨。 經(jīng)常有香客問我,道長跨跨,這世上最難降的妖魔是什么潮峦? 我笑而不...
    開封第一講書人閱讀 58,925評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮勇婴,結(jié)果婚禮上忱嘹,老公的妹妹穿的比我還像新娘。我一直安慰自己耕渴,他們只是感情好拘悦,可當(dāng)我...
    茶點故事閱讀 67,942評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著橱脸,像睡著了一般础米。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上添诉,一...
    開封第一講書人閱讀 51,727評論 1 305
  • 那天屁桑,我揣著相機(jī)與錄音,去河邊找鬼栏赴。 笑死掏颊,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播乌叶,決...
    沈念sama閱讀 40,447評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼盆偿,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了准浴?” 一聲冷哼從身側(cè)響起事扭,我...
    開封第一講書人閱讀 39,349評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎乐横,沒想到半個月后求橄,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,820評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡葡公,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,990評論 3 337
  • 正文 我和宋清朗相戀三年罐农,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片催什。...
    茶點故事閱讀 40,127評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡涵亏,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出蒲凶,到底是詐尸還是另有隱情气筋,我是刑警寧澤,帶...
    沈念sama閱讀 35,812評論 5 346
  • 正文 年R本政府宣布旋圆,位于F島的核電站宠默,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏灵巧。R本人自食惡果不足惜搀矫,卻給世界環(huán)境...
    茶點故事閱讀 41,471評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望刻肄。 院中可真熱鬧瓤球,春花似錦、人聲如沸肄方。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽权她。三九已至,卻和暖如春逝薪,著一層夾襖步出監(jiān)牢的瞬間隅要,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評論 1 272
  • 我被黑心中介騙來泰國打工董济, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留步清,地道東北人。 一個月前我還...
    沈念sama閱讀 48,388評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像廓啊,于是被迫代替她去往敵國和親欢搜。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,066評論 2 355