本项目只用到核心的发消息功能
卡夫卡特点;高吞吐量,消息持久化,高可靠性,高扩展性
术语:
Broker –kafka的服务器
Zookeeper – 管理集群,卡夫卡内置
Topic —主题,发布者把东西发到的空间 (消息队列实现方式两种:点对点(上次的消费者-生产者模式,一个消费者对应一个生产者);发布订阅模式:发布者把东西发到一个地方,可以有多个消费者同时读到,这个是卡夫卡的模式。)
Partition:topic下面的分区,从前往后
Offset:消息在分区里面的索引
Leader Replica:主副本(备份),为了数据的可靠性,每个分区存多个副本。提高容错率。
主副本的能力较强,当有请求时,主副本可以响应。
Follower Replica: 从副本,只是备份。当主副本没了以后,从副本copy一份过去。
配置config
zookeeper:
server:
开启zookeeper
D:\WorkPlace\kafka_2.12-2.3.0>bin\windows\zookeeper-server-start.bat config\zookeeper.properties
开启kafaka
D:\WorkPlace\kafka_2.12-2.3.0>bin\windows\kafka-server-start.bat config\server.properties
使用kafaka
创建主题
bin\windows\kafka-topics.bat --create —bootstrap-server localhost:9092 --replication-factor 1 --partition 1 --topic test
1
查看指定服务器下所有主题
bin\windows\kafka-topics.bat --bootstrap-server localhost:9092
1
调用生产者发送消息
bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
1
输入hello,回车后再输入world。
再开一个命令窗口,
bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
1
就能读到生产者发送的hello和world等。