Written by
in
Apache Kafka เป็น distributed streaming platform [1] กล่าวคือ สามารถ Publish และ Subscribe ข้อมูลแบบ Streaming ได้ คล้ายๆกับ Message Queue หรือ Enterprise Messaging System ระบบนี้ใช้ได้ทั้งเป็น Real-time Streaming Data Pipeline และ สร้าง Streaming Application ได้ Apache Kafka ออกแบบมาให้สามารถทำงานเป็นแบบ Cluster โดยเก็บข้อมูลเป็น Stream of Record ซึ่งจัดหมวดหมู่ในรูปของ Topics ข้อมูลแต่ละ Record ประกอบด้วบ Key, Value และ timestamp
เอาเป็นว่า ระบบนี้เอาไว้สำหรับรองรับการส่งข้อมูลแนวๆ Streaming มาเพื่อทำการวิเคราะห์แบบ Real-Time แทนที่จะต้องบริหารเองก็แล้วกัน แถมด้วยความสามารถในการ Subscribe ข้อมูล สามารถย้อนไปดูข้อมูลก่อนหน้าได้ (ตามขอบเขตเวลาที่กำหนด) มาติดตั้งกัน
บทความนี้ ทดสอบบน Ubuntu 16.04
wget http://www-eu.apache.org/dist/kafka/0.10.2.0/kafka_2.11-0.10.2.0.tgz tar -zxvf kafka_2.11-0.10.2.0.tgz cd kafka_2.11-0.10.2.0
bin/zookeeper-server-start.sh config/zookeeper.properties &
แล้วจึง สั่ง Start Kafka
bin/kafka-server-start.sh config/server.properties &
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
ซึ่งในที่นี้ จะได้ Topic ชื่อ test ทำงานบน Zookeeper บน Localhost ที่ Port 2181 ลองใช้คำสั่งต่อไปนี้เพื่อดู Topic ทั้งหมด
bin/kafka-topics.sh --list --zookeeper localhost:2181
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
แล้วลองพิมพ์ข้อความอะไรลงไปดู เช่น
Hello World This is a book Blah Blah
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
ก็จะเห็นได้ว่า สามารถเรียกดูสิ่งที่ส่งเข้าไปใน Topic “test” ตั้งแต่เริ่มต้นได้
ตรงนี้ยังไม่แปลกอะไร และไม่น่าตื่นเต้นอะไร บทความต่อไปจะกล่าวถึงการสร้างเป็น Cluster แล้วก็ทำงานกับ หลายๆ Producer และ หลายๆ Consumer พร้อมๆกัน
Reference
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Δ
Leave a Reply