Files
QingLong/AI/AiService/Doc/2、安装kafka.md
2025-08-15 09:13:13 +08:00

33 lines
861 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

- **安装**
在 $docker-compose.yml$ 文件所在目录下,运行以下命令启动 $Kafka$ 和 $Zookeeper$
```shell
docker-compose up -d
```
- 验证 $Kafka$ 是否正常运行
```shell
docker ps
```
输出应显示 $kafka$ 容器正在运行。
- **创建测试主题**
```shell
docker exec -it kafka kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
```
- **列出主题**
```shell
docker exec -it kafka kafka-topics.sh --list --bootstrap-server localhost:9092
```
- **生产消息**
```shell
docker exec -it kafka kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092
```
- **消费消息**
```shell
docker exec -it kafka kafka-console-consumer.sh --topic test-topic --bootstrap-server localhost:9092 --from-beginning
```