Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Distributed Message Service for RocketMQ/ Getting Started/ Getting Started with RocketMQ to Produce and Consume Messages

Getting Started with RocketMQ to Produce and Consume Messages

Updated on 2025-01-26 GMT+08:00

This document takes the example of creating a RocketMQ instance with SSL enabled and accessing it on a client in the same VPC as the instance over a private network for message production and consumption to get you quickly started with Distributed Message Service (DMS) for RocketMQ.

Procedure

Figure 1 Procedure for using DMS for RocketMQ
  1. Step 1: Preparations

    Before creating a RocketMQ instance, an authenticated Huawei Cloud account with balance, users with required permissions, a set of Virtual Private Cloud (VPC) and subnet, a security group, an Elastic Cloud Server (ECS), and an environment should be prepared.

  2. Step 2: Create a RocketMQ Instance

    Enable SSL, disable ACL, and configure the created VPC and subnet, and security group.

  3. Step 3: Create a Topic

    After an instance is created, create a topic for sending and receiving messages.

  4. Step 4: Connect to a RocketMQ Instance to Produce and Consume Messages

    On the client, connect to the instance and use commands to produce and consume messages.

Step 1: Preparations

  1. Sign up for a HUAWEI ID.

    If you already have a Huawei account, skip this step. If you do not have one, see Signing Up for a HUAWEI ID and Enabling Huawei Cloud Services.

  2. Grant RocketMQ instance permissions.

    The RocketMQ administrator permission DMS FullAccess is required. For details, see Creating a User and Granting DMS for RocketMQ Permissions.

  3. Create a VPC and subnet.

    CAUTION:

    The VPC must be created in the same region as the RocketMQ instance.

    A RocketMQ instance runs in a Virtual Private Cloud (VPC). Before creating an instance, ensure that a VPC is available. For details about how to create a VPC and a subnet, see Creating a VPC and Subnet.

  4. Create a security group.

    See Creating a Security Group.

    To connect to RocketMQ instances, add the security group rules described in Table 1.

    Table 1 Security group rules

    Direction

    Protocol

    Port

    Source

    Description

    Inbound

    TCP

    8100

    IP address or IP address range of the RocketMQ client

    The port is used for private network access to instances using TCP.

    Inbound

    TCP

    8080

    The port is used for private network access to instances using gRPC.

    Inbound

    TCP

    10100

    The port is used for private access to service nodes using TCP.

    NOTE:

    After a security group is created, its default inbound rule allows communication among ECSs within the security group and its default outbound rule allows all outbound traffic. In this case, you can access a RocketMQ instance within a VPC, and do not need to add rules according to Table 1.

  5. Create an elastic cloud server (ECS) and configure environment variables.

    The following takes a Linux ECS as an example. For more information about how to install JDK and configure the environment variables for a Windows ECS, please search the Internet.

    1. Log in to the console, click in the upper left corner, click Elastic Cloud Server under Computing, and then create an ECS.

      For details, see Purchasing a Custom ECS. If you already have an available ECS, skip this step.

    2. Log in to an ECS as user root.
    3. Install the JDK and configure the environment variables JAVA_HOME and PATH.
      1. Download the JDK.
        NOTE:

        Use Oracle JDK instead of ECS's default JDK (for example, OpenJDK), because ECS's default JDK may not be suitable for the sample project. Obtain Oracle JDK 1.8.111 or later from Oracle's official website.

      2. Run the following command to decompress the JDK package.
        tar -zxvf jdk-8u321-linux-x64.tar.gz

        Change jdk-8u321-linux-x64.tar.gz to your JDK version.

      3. Run the following command to edit the environment variable file .bash_profile:
        vim ~/.bash_profile
      4. Add the following content to the environment variable file:
        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.

      5. Press Esc to exit the editing mode and run the following command to save the environment variable file:
        :wq
      6. Run the following command to make the environment variables take effect:
        source .bash_profile
    4. Run the following command to check whether the JDK is successfully installed.
      java -version
      If the following information is displayed, the JDK is installed successfully:
      java version "1.8.0_321"
    5. Run the following command to download the rocketmq-tutorial sample software package.
      wget https://dms-demos.obs.cn-north-1.myhuaweicloud.com/rocketmq-tutorial.zip
    6. Run the following command to decompress rocketmq-tutorial.
      unzip rocketmq-tutorial.zip

Step 2: Create a RocketMQ Instance

Before using RocketMQ for message production and consumption, create a RocketMQ instance. The VM resource in the instance store topics.

  1. Go to the Buy Instance page.
  2. On the Quick Config tab page, set basic instance configurations shown in Figure 2. Table 2 lists the configuration details.

    Table 2 Setting instance basics

    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 RocketMQ instances 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 an AZ.

    Figure 2 Setting instance basics

  3. 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

    Choose Recommended > Starter. Basic small-specs instances are compatible with open-source RocketMQ. Ideal for cost-sensitive services or pre-release environments that are tolerant to latency or limited performance.

    Storage Space

    Select the disk type and specify the disk size as required.

    After the instance is created, you cannot change the disk type.

    Select Ultra-high I/O and enter 200.

    Figure 3 Setting the instance specifications and storage space

  4. Configure the instance network as shown in Figure 4. For details, see Table 4.

    Table 4 Configuring the instance network

    Parameter

    Description

    VPC

    After the RocketMQ instance is created, its VPC cannot be changed.

    Select the VPC prepared in 3.

    Subnet

    After the RocketMQ instance is created, its subnet cannot be changed.

    Select the subnet prepared in 3.

    Security Group

    Select the security group prepared in 4.

    Figure 4 Configuring the instance network

  5. Set the instance access mode as shown in Figure 5. For details, see Table 5.

    Table 5 Setting the instance access mode

    Parameter

    Description

    Public Network Access

    EIPs are required to enable public access. Do not enable it here.

    Encryption Mode

    Ciphertext access with high security, but lower performance. Select SSL.

    Figure 5 Setting the instance access mode

  6. Configure Advanced Settings, as shown in Figure 6. For details, see Table 6. Retain default settings for other parameters.

    Table 6 Configuring advanced instance 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 rocketmq-test.

    Enterprise Project

    This parameter is for enterprise users. An enterprise project manages project resources in groups. Enterprise projects are logically isolated.

    Select "default".

    ACL

    Enabling ACL can manage permissions for message production and consumption. Do not enable it here.

    Tags

    Identifiers of the RocketMQ instance. Skip it here.

    Description

    Additional information about the instance. Skip it.

    Figure 6 Configuring advanced instance settings

  7. Click Confirm.
  8. Confirm the instance information, read and agree to the Huawei Cloud Customer Agreement, and submit the request.
  9. Return to the instance list and check whether the RocketMQ 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. Then create a new one. If the instance creation fails again, contact customer service.

  10. After the instance is created, click its name to go to the instance basic information page.
  11. Record the instance connection addresses for later use.

    Figure 7 Recording instance connection addresses

Step 3: Create a Topic

A topic is the basic unit for sending and receiving messages. After creating a RocketMQ instance, you must manually create topics before creating and retrieving messages.

  1. Click a RocketMQ instance to go to the instance basic information page.
  2. In the navigation pane, choose Topics.
  3. Click Create Topic.
  4. Configure the topic name and other parameters by referring to Table 7.

    Table 7 Topic parameters

    Parameter

    Description

    Topic Name

    Enter a topic name. Enter Topic01 here.

    Message Type

    Select the message type. Select Normal here.

    Description

    Additional information about the topic. Skip it.

    Figure 8 Creating a topic

  5. Click OK.

Step 4: Connect to a RocketMQ Instance to Produce and Consume Messages

  1. Go to the rocketmq-tutorial/bin directory on the ECS.

    cd rocketmq-tutorial/bin

  2. Produce normal messages by the following commands.

    The following is a command example:
    JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "10.xxx.xxx.89:8100;10.xxx.xxx.144:8100" -t Topic01 -p "hello rocketmq"
    • 10.xxx.xxx.89:8100;10.xxx.xxx.144:8100: the connection address of the RocketMQ instance, that is, the connection address in 11.
    • Topic01: name of the topic created in 4 for the RocketMQ instance.
    • hello rocketmq: the produced message content.

  3. Consume normal messages by the following commands.

    The following is a command example:
    JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "10.xxx.xxx.89:8100;10.xxx.xxx.144:8100" -t Topic01

    The content of BODY is the consumed message content.

    To stop consuming messages, press Ctrl+C to exit.

Related Information

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback