Linux Kafka配置后可按以下步驟測試:
基礎功能測試
bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1bin/kafka-topics.sh --list --bootstrap-server localhost:9092echo "Hello Kafka" | bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:9092服務狀態驗證
jps(需看到Kafka進程)netstat -tulnp | grep 9092(確認9092端口被監聽)性能測試(可選)
bin/kafka-producer-perf-test.sh --topic perf-test --num-records 1000000 --record-size 1024 --throughput 5000 --producer-props bootstrap.servers=localhost:9092bin/kafka-consumer-perf-test.sh --topic perf-test --messages 1000000 --bootstrap-server localhost:9092集群環境測試(若為集群部署)
bin/kafka-topics.sh --describe --topic test-topic --bootstrap-server <任意節點IP>:9092說明:若使用KRaft模式(無ZooKeeper),需將--zookeeper參數替換為--bootstrap-server。