Example: Produce & Consume Message
This document provides a step-by-step guide to performing basic message production and consumption tests on an AutoMQ cluster using Kafka CLI tools. The Kafka CLI tools run via the Docker image supplied by AutoMQ.
Prerequisites
Before conducting message transmission tests, ensure the following prerequisites are met:
Complete the installation and deployment of the AutoMQ cluster. You can refer to the following methods for installing and deploying AutoMQ:
Additionally, the host running the test program must fulfill the following conditions:
-
Linux/Mac/Windows Subsystem for Linux
-
Docker
- Deploy Multi-Nodes Test Cluster on Docker
- Deploy Multi-Nodes Cluster on Linux
If the previous AutoMQ cluster was deployed according to the guidelines in Deploy Multi-Nodes Test Cluster on Docker▸, the obtained cluster bootstrap address will resemble "server1:9092,server2:9092,server3:9092," and the AutoMQ cluster will be positioned within the "automq_net" Docker network.
Please substitute the bootstrap-server address below with the actual address of the deployed cluster.
Create Topic
docker run --network automq_net automqinc/automq:latest /bin/bash -c "/opt/kafka/kafka/bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server server1:9092,server2:9092,server3:9092"
Send Messages
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 server1:9092,server2:9092,server3:9092"
Consume Messages
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 server1:9092,server2:9092,server3:9092"
If the previous AutoMQ cluster was deployed referencing Deploy Multi-Nodes Cluster on Linux▸, then the obtained cluster bootstrap address would be something like "192.168.0.1:9092,192.168.0.2:9092,192.168.0.3:9092."
Please replace the bootstrap-server address below with the actual cluster address based on the deployment configuration.
Create Topic
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,192.168.0.3:9092"
Send Messages
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,192.168.0.3:9092"
Consume Messages
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,192.168.0.3:9092"