🚡 Kafka
参考
MQ
- 消息队列,程序间通信的一种方式
why
-
解耦
-
异步
-
削峰
how
waht
安装
-
使用 docker 启动
Bash 1
sudo docker run -d --rm -p 9092:9092 apache/kafka
-
创建一个主题
Bash 1
sudo docker exec -it <container_id> /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test-topic
-
生产者
Bash 1
sudo docker exec -it <container_id> /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test-topic
输入消息后按
Ctrl+C
结束 -
消费者
Bash 1
sudo docker exec -it <container_id> /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning
C++
Docker | |
---|---|
1 2 3 4 5 |
|
生成镜像:
Bash | |
---|---|
1 |
|
编译:
Bash | |
---|---|
1 2 |
|
消费者:
Bash | |
---|---|
1 |
|
生产者:
Bash | |
---|---|
1 |
|