Getting Started with RabbitMQ for Message Production and Consumption
This section takes an example to get you started with DMS for RabbitMQ. The example creates a RabbitMQ instance with SSL disabled, and accesses it over a private network on a client within a VPC. As a result, messages can be produced and consumed.
- Step 1: Preparations
A RabbitMQ instance runs in a Virtual Private Cloud (VPC). Before creating a RabbitMQ instance, ensure that a VPC is available.
- Step 2: Creating a RabbitMQ Instance
You can select the specifications and quantity when creating a RocketMQ instance.
- Step 3: Accessing an Instance for Message Production and Consumption
A client connects to the instance with SSL disabled using the demo provided by RabbitMQ.
Step 1: Preparations
- Register with Huawei Cloud and complete real-name authentication.
For details, see Signing up for a HUAWEI ID and Enabling Huawei Cloud Services and Real-Name Authentication.
If you already have a Huawei account and have completed real-name authentication, skip this step.
- Top up the account.
Ensure that your account has sufficient balance before creating a RabbitMQ instance. For details about how to top up an account, see Topping Up an Account.
- Grant RabbitMQ instance permissions.
To achieve fine-grained management of your cloud resources, create Identity and Access Management (IAM) user groups and users and grant specified permissions to the users. For more information, see Creating a User and Granting DMS for RabbitMQ Permissions.
- Create a VPC and subnet.
Before creating a RabbitMQ instance, ensure that a VPC and a subnet are available. For details about how to create a VPC and subnet, see Creating a VPC and Subnet.
The VPC must be created in the same region as the RabbitMQ instance.
- Create a security group and add security group rules.
Before creating a RabbitMQ instance, ensure that a security group is available. For details about how to create a security group, see Creating a Security Group.
To connect to RabbitMQ instances, add the security group rules described in Table 1. Other rules can be added based on site requirements.Table 1 Security group rules Direction
Protocol
Port
Source address
Description
Inbound
TCP
5672
0.0.0.0/0
Accessing a RabbitMQ instance (SSL disabled)
After a security group is created, it has a default inbound rule that allows communication among ECSs within the security group and a default outbound rule that allows all outbound traffic. If you access your RabbitMQ instance over a private network within a VPC, you do not need to add the rules described in Table 1.
- Construct a client for message production and consumption.
This section uses a Linux elastic cloud server (ECS) as the client. Before creating a RabbitMQ instance, create an ECS with elastic IPs (EIPs), install JDK, and configure the environment variables.
- Log in to the console, click in the upper left corner, click Elastic Cloud Server under Computing, and then create an ECS.
For details about how to create an ECS, see Purchasing a Custom ECS. If you already have an available ECS, skip this step.
- Log in to an ECS as user root.
- Install Java JDK and configure the environment variables JAVA_HOME and PATH.
- Download a JDK.
Use Oracle JDK instead of ECS's default JDK (for example, OpenJDK), because ECS's default JDK may not be suitable. Obtain Oracle JDK 1.8.111 or later from Oracle's official website.
- Decompress the JDK.
tar -zxvf jdk-8u321-linux-x64.tar.gz
Change jdk-8u321-linux-x64.tar.gz to your JDK version.
- Open the .bash_profile file.
vim ~/.bash_profile
- Add the following content:
export JAVA_HOME=/opt/java/jdk1.8.0_321 export PATH=$JAVA_HOME/bin:$PATH
Change /opt/java/jdk1.8.0_321 to the path where you install JDK.
- Press Esc. Enter the following line and press Enter. Save the .bash_profile file and exit.
:wq
- Run the following command to make the change take effect:
source .bash_profile
- Check whether the JDK is installed.
java -version
If the following message is returned, the JDK is installed.java version "1.8.0_321"
- Download a JDK.
- Log in to the console, click in the upper left corner, click Elastic Cloud Server under Computing, and then create an ECS.
Step 2: Creating a RabbitMQ Instance
- Go to the Buy Instance page.
- On the Quick Config tab page, set basic instance configurations shown in Figure 2. Table 2 lists the configuration details.
Table 2 Setting basic instance configurations Parameter
Description
Billing Mode
Select Pay-per-use, which is a postpaid mode. You can pay after using the service, and will be billed for your usage duration. The fees are calculated in seconds and settled by hour.
Region
DMS for Kafka in different regions cannot communicate with each other over an intranet. Select a nearest location for low latency and fast access.
Select AP-Singapore.
AZ
An AZ is a physical region where resources use independent power supply and networks. AZs are physically isolated but interconnected through an internal network.
Select AZ1.
- Set the instance specifications and storage space, as shown in Figure 3. For details, see Table 3.
Table 3 Setting the instance specifications and storage space Parameter
Description
Bundle
Select Test: Single-node instances with mini specs, saving resources and costs for testing or debugging. Note that high availability is unavailable.
Storage Space per Broker
Select the disk type and specify the disk size as required.
Total storage space = Storage space per broker × Broker quantity. The disk type cannot be changed once the instance is created.
Select Ultra-high I/O and enter 100.
- Configure the instance network as shown in Figure 4. For details, see Table 4.
Table 4 Configuring instance network Parameter
Description
VPC
After the RabbitMQ instance is created, its VPC cannot be changed.
Select the VPC prepared in 4.
Subnet
After the RabbitMQ instance is created, its subnet cannot be changed.
Select the subnet prepared in 4.
Security Group
Select the security group prepared in 5.
- Set the instance access mode. Retain the default setting.
- Set the instance authentication method as shown in Figure 5. For details, see Table 5.
Table 5 Configuring the instance authentication method Parameter
Description
RabbitMQ Authentication Username
Enter the username used for accessing the instance.
A username should contain 4 to 64 characters, start with a letter, and contain only letters, digits, hyphens (-), and underscores (_).
Enter "test".
Password
Enter the password used for accessing the instance.
A password must meet the following requirements:
- Contains 8 to 32 characters.
- Contains at least three types of the following characters: uppercase letters, lowercase letters, digits, and special characters `~! @#$ %^&*()-_=+\|[{}];:'",<.>? and spaces, and cannot start with a hyphen (-).
- Cannot be the username spelled forwards or backwards.
- Configure Advanced Settings, as shown in Figure 6. For details, see Table 6. Retain default settings for other parameters.
Table 6 Configuring instance advanced settings Parameter
Description
Instance Name
You can customize a name that complies with the rules: 4–64 characters; starts with a letter; can contain only letters, digits, hyphens (-), and underscores (_).
Enter "rabbitmq-test".
Enterprise Project
This parameter is for enterprise users. An enterprise project manages project resources in groups. Enterprise projects are logically isolated.
Select default.
- Click Confirm.
- Confirm the instance information, read and agree to the Huawei Cloud Customer Agreement, and then submit the request.
- Return to the instance list and check whether the instance has been created.
It takes 3 to 15 minutes to create an instance. During this period, the instance status is Creating.
- If the instance is created successfully, its status changes to Running.
- If the instance is in the Creation failed state, delete it and try purchasing another one. If the instance purchase fails again, contact customer service.
- After the instance is created, click its name to go to the instance details page.
- In the Connection area, view and record the connection address.
Figure 7 Connection address
Step 3: Accessing an Instance for Message Production and Consumption
- Go to the root directory on the ECS and download the sample project code RabbitMQ-Tutorial.zip.
wget https://dms-demo.obs.cn-north-1.myhuaweicloud.com/RabbitMQ-Tutorial.zip
/root is the path for storing the sample project code. Change it to the actual path if needed.
- Run the following command to decompress RabbitMQ-Tutorial.zip:
unzip RabbitMQ-Tutorial.zip
- Run the following command to navigate to the RabbitMQ-Tutorial directory, which contains the precompiled JAR file:
cd RabbitMQ-Tutorial
- Produce messages using the sample project.
java -cp .:rabbitmq-tutorial.jar Send ${host} ${port} ${user} ${password}
Description:
- host: connection address obtained in the instance creation.
- port: port of the RabbitMQ instance. Enter 5672.
- user: username set in instance creation.
- password: password set in instance creation.
Sample message production:
[root@ecs-test RabbitMQ-Tutorial]# java -cp .:rabbitmq-tutorial.jar Send 192.168.xx.40 5672 test Zxxxxxxs [x] Sent 'Hello World!' [root@ecs-test RabbitMQ-Tutorial]# java -cp .:rabbitmq-tutorial.jar Send 192.168.xx.40 5672 test Zxxxxxxs [x] Sent 'Hello World!'
- Consume messages using the sample project.
java -cp .:rabbitmq-tutorial.jar Recv ${host} ${port} ${user} ${password}
Description:
- host: connection address obtained in the instance creation.
- port: port of the RabbitMQ instance. Enter 5672.
- user: username set in instance creation.
- password: password set in instance creation.
Sample message consumption:
[root@ecs-test RabbitMQ-Tutorial]# java -cp .:rabbitmq-tutorial.jar Recv 192.168.xx.40 5672 test Zxxxxxxs [*] Waiting for messages. To exit press CTRL+C [x] Received 'Hello World!' [x] Received 'Hello World!'
Press Ctrl+C to cancel.
Related Information
- Learn more about the basic concepts of RabbitMQ.
- Learn more about Distributed Message Service for RabbitMQ Pricing.
- To log in to RabbitMQ management UI, see Connecting to the Management Address of a RabbitMQ Instance.
- To view monitoring metrics of a RabbitMQ instance, see Viewing Metrics.
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