Step 4: Connect to a RocketMQ Instance to Create and Retrieve Messages
This section describes how to use TCP to connect to a RocketMQ instance with SSL in CLI mode.
Prerequisites
- A RocketMQ instance has been created following the instructions in Step 2: Create a RocketMQ Instance, and the instance metadata addresses have been recorded.
- Security group rules have been configured.
- A topic has been created and you have obtained the topic name.
- An ECS has been created. For intra-VPC access, ensure that its VPC, subnet, and security group configurations are the same as those of the RocketMQ instance.
- You have installed the JDK and configured the environment variables. For details, see Step 1: Prepare the Environment.
Accessing the Instance with CLI
- Download the rocketmq-tutorial software package.
wget https://dms-demo.obs.cn-north-1.myhuaweicloud.com/rocketmq-tutorial.zip
- Decompress the rocketmq-tutorial package.
unzip rocketmq-tutorial.zip
- Go to the rocketmq-tutorial/bin directory.
cd rocketmq-tutorial/bin
- Create normal messages using the sample project.
JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "${Connection addresses}" -t ${Topic name} -p "hello rocketmq"
Parameter description:
- Connection addresses: specifies the metadata address of a RocketMQ instance.
- Topic name: name of the topic created for the RocketMQ instance
In the following example, 100.xxx.xxx.89:8200;100.xxx.xxx.144:8200 are the connection addresses to the RocketMQ instance, and topic-test is the topic name.
JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "100.xxx.xxx.89:8200;100.xxx.xxx.144:8200" -t topic-test -p "hello rocketmq"
Press Ctrl+C to exit.
- Retrieve normal messages using the sample project.
JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "${Connection addresses}" -t ${Topic name}
Parameter description:
- Connection addresses: specifies the metadata address of a RocketMQ instance.
- Topic name: name of the topic created for the RocketMQ instance
In the following example, 100.xxx.xxx.89:8200;100.xxx.xxx.144:8200 are the connection addresses to the RocketMQ instance, and topic-test is the topic name.
JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "100.xxx.xxx.89:8200;100.xxx.xxx.144:8200" -t topic-test
To stop consuming messages, press Ctrl+C to exit.
- Create messages with traces using the sample project.
JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "${Connection addresses}" -t ${Topic name} -p "hello rocketmq" -m true
Parameter description:
- Connection addresses: specifies the metadata address of a RocketMQ instance.
- Topic name: name of the topic created for the RocketMQ instance
In the following example, 100.xxx.xxx.89:8200;100.xxx.xxx.144:8200 are the connection addresses to the RocketMQ instance, and topic-test is the topic name.
JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "100.xxx.xxx.89:8200;100.xxx.xxx.144:8200" -t topic-test -p "hello rocketmq" -m true
Press Ctrl+C to exit.
- Retrieve messages and send the message traces using the sample project.
JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "${Connection addresses}" -t ${Topic name} -m true
Parameter description:
- Connection addresses: specifies the metadata address of a RocketMQ instance.
- Topic name: name of the topic created for the RocketMQ instance
In the following example, 100.xxx.xxx.89:8200;100.xxx.xxx.144:8200 are the connection addresses to the RocketMQ instance, and topic-test is the topic name.
JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "100.xxx.xxx.89:8200;100.xxx.xxx.144:8200" -t topic-test -m true
Press Ctrl+C to exit.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot