第一关kafka-初体验
时间: 2023-12-02 11:42:28 浏览: 59
以下是kafka的初体验步骤:
1. 下载并解压kafka
```shell
wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.8.0/kafka_2.13-2.8.0.tgz
tar -xzf kafka_2.13-2.8.0.tgz
cd kafka_2.13-2.8.0
```
2. 启动kafka服务
```shell
# 启动zookeeper服务
bin/zookeeper-server-start.sh config/zookeeper.properties &
# 启动kafka服务
bin/kafka-server-start.sh config/server.properties &
```
3. 创建一个主题
```shell
bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092
```
4. 发送一些消息
```shell
bin/kafka-console-producer.sh --topic test --bootstrap-server localhost:9092
>Hello, Kafka!
>This is my first message.
```
5. 从主题中消费消息
```shell
bin/kafka-console-consumer.sh --topic test --from-beginning --bootstrap-server localhost:9092
Hello, Kafka!
This is my first message.
```