天天看點

[Spark][kafka]kafka 生産者,消費者 互動例子

[Spark][kafka]kafka 生産者,消費者 互動例子

# pwd

/usr/local/kafka_2.11-0.10.0.1/bin

建立topic:

# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic device_status

WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.

Created topic "device_status".

#

檢視topic:

# ./kafka-topics.sh --list --zookeeper localhost:2181

device_status

生産者生成消息:

# ./kafka-console-producer.sh --broker-list localhost:9092 --topic device_status

消費者獲得消息:

# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic device_status --from-beginning

繼續閱讀