Kafka command line setup producer & consummer#

Nếu bạn cần test nhanh kết nối của kafka hoặc gặp khó khăn trong việc setup các Kafka client sdk, có thể sử dụng bộ công cụ command line của kafka. Trước hết bạn xem cách cài đặt kafka command line tool

Pre-condition:

  • OS: Ubuntu

  • Cài đặt Sun Kafka Highway

  • Download api key file and set up Config file

  • Download Kafka client tool

Bước 1: Setup consumer#

sh kafka-console-consumer.sh --bootstrap-server <bootstrap-url> --topic <topic-name> --consumer.config ./config.properties

Sau khi set up, terminal sẽ hold và in ra message khi có message.

Bước 2: Setup producer#

sh kafka-console-producer.sh --bootstrap-server <bootstrap-url> --topic <topic-name> --producer.config ./config.properties

Sau khi set up, bạn có thể gửi nhập message và gửi đi, ngay sau đó consumer sẽ nhận được và in ra message

Bước 3: Send a message#

Producer gửi mesage lên broker

Consumer nhận được messsage

Bước 4: Send message từ ứng dụng#

Trong thực tế khi phát triển phần mềm, các message sẽ được gửi từ application lên broker và application khác sẽ nhận message và xử lí

Thực hiện send mesage qua ứng dụng bằng postman api

Lúc này consumer sẽ liên tục nhận được message và in ra