示例:验证收发消息功能
本文旨在指导您完成一个简单的消息发送和接收负载,以验证 AutoMQ 的基本功能。
以 在 Linux 主机上以集群方式部署▸ 方式成功安装 AutoMQ 后,你会得到类似以下形式的 Bootstrap Server 地址列表:
192.168.0.1:9092,192.168.0.2:9092
如果你是通过 本地部署▸ 安装的,Bootstrap Server 地址会是:
broker1:9092,broker2:9092
在所有步骤中,请确保将 Bootstrap Server 地址替换为你实际获取的地址。
前置条件
Linux/Mac/Windows Subsystem for Linux
Docker
如果下载容器镜像速度慢,请参照 Docker Hub 镜像加速▸
- Deploy Locally
- Cluster Deployment on Linux
创建 Topic
CMD='docker run --network automq_net automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server broker1:9092,broker2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
发送消息
CMD='docker run -it --network automq_net automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server broker1:9092,broker2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
消费消息
CMD='docker run --network automq_net automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server broker1:9092,broker2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
创建 Topic
CMD='docker run automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server 192.168.0.1:9092,192.168.0.2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
发送消息
CMD='docker run -it automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server 192.168.0.1:9092,192.168.0.2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD
消费消息
CMD='docker run automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server 192.168.0.1:9092,192.168.0.2:9092"'; [ "$(uname)" = "Linux" ] && eval "sudo $CMD" || eval $CMD