tencent cloud

TDMQ for RocketMQ

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Introduction and Selection of the TDMQ Product Series
What Is TDMQ for RocketMQ
Strengths
Scenarios
Product Series
Comparison with Open-Source RocketMQ
High Availability
Quotas and Limits
Supported Regions
Basic Concepts
Billing
Billing Overview
Pricing
Billing Examples
Pay-as-you-go Switch to Monthly Subscription (5.x)
Renewal
Viewing Consumption Details
Refund
Overdue Payments
Getting Started
Getting Started Guide
Preparations
Step 1: Creating TDMQ for RocketMQ Resources
Step 2: Using the SDK to Send and Receive Messages (Recommended)
Step 2: Running the TDMQ for RocketMQ Client (Optional)
Step 3: Querying Messages
Step 4: Deleting Resources
User Guide
Usage Process Guide
Configuring Account Permissions
Creating the Cluster
Configuring the Namespace
Configuring the Topic
Configuring the Group
Connecting to the Cluster
Managing Messages
Managing the Cluster
Viewing Monitoring Data and Configuring Alarms
Cross-Cluster Message Replication
Use Cases
Naming Conventions for Common Concepts of TDMQ for RocketMQ
RocketMQ Client Use Cases
RocketMQ Performance Load Testing and Capacity Assessment
Access over HTTP
Client Risk Descriptions and Update Guide
Migration Guide for TencentCloud API Operations Related to RocketMQ 4.x Cluster Roles
Migration Guide
Disruptive Migration
Seamless Migration
Developer Guide
Message Types
Message Filtering
Message Retries
POP Consumption Mode (5.x)
Clustering Consumption and Broadcasting Consumption
Subscription Relationship Consistency
Traffic Throttling
​​API Reference(5.x)
History
API Category
Making API Requests
Topic APIs
Consumer Group APIs
Message APIs
Role Authentication APIs
Hitless Migration APIs
Cloud Migration APIs
Cluster APIs
Data Types
Error Codes
​​API Reference(4.x)
SDK Reference
SDK Overview
5.x SDK
4.x SDK
Security and Compliance
Permission Management
CloudAudit
Deletion Protection
FAQs
4.x Instance FAQs
Agreements
TDMQ for RocketMQ Service Level Agreement
Contact Us

Using the Node.js SDK

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-01-23 17:52:24

Scenarios

This document uses the Node.js SDK as an example to describe how to send and receive messages through an open-source software development kit (SDK), helping you better understand the complete process of sending and receiving messages.

Prerequisites

You have obtained the client connection parameters as instructed in SDK Overview.
You have installed the Node.js development environment, such as npm.

Operation Steps

Step 1: Installing the Node.js SDK in the Project

1. Install the SDK:
npm i rocketmq-client-nodejs
2. After installation, relevant dependencies are included in the package.json file of the project.

Step 2: Producing Messages

import { Producer } from 'rocketmq-client-nodejs';

const producer = new Producer({
endpoints: 'rmq-xxx.rocketmq.gz.qcloud.tencenttdmq.com:8080', // Tencent Cloud access point.
sessionCredentials: {
accessKey: 'yourAccessKey', // ak
accessSecret: 'yourSecretKey', // sk
}
});
await producer.startup();

const receipt = await producer.send({
topic: 'TopicTest', // Topic created in the console.
body: Buffer.from(JSON.stringify({
hello: 'rocketmq-client-nodejs world',
now: Date(),
})),
});
console.log(receipt);
Parameter
Description
accessKey
Role token. You can copy the token from the AccessKey column on the Cluster Permissions page in the console.
accessSecret
Role name. You can copy the role name from the SecretKey column on the Cluster Permissions page in the console.
endpoints
Cluster access address. You can obtain the access address from the Access Information module on the Cluster Basic Information page in the console.
topic
Topic name. You can copy the name from the Topic Management page in the console.

Step 3: Consuming Messages

The Node.js SDK supports Simple Consumer. The following sample code uses Simple Consumer as an example:
import {SimpleConsumer } from 'rocketmq-client-nodejs';
const simpleConsumer = new SimpleConsumer({
endpoints: 'rmq-xxx.rocketmq.gz.qcloud.tencenttdmq.com:8080', // Tencent Cloud access point.
sessionCredentials: {
accessKey: 'yourAccessKey', // ak
accessSecret: 'yourSecretKey', // sk
},
consumerGroup: 'nodejs-demo-group', // Consumer group.
subscriptions: new Map().set('TopicTest', '*'),
});
await simpleConsumer.startup();

const messages = await simpleConsumer.receive(20);
console.log('got %d messages', messages.length);
for (const message of messages) {
console.log(message);
console.log('body=%o', message.body.toString());
await simpleConsumer.ack(message);
}
Parameter
Description
accessKey
Role token. You can copy the token from the AccessKey column on the Cluster Permissions page in the console.
accessSecret
Role name. You can copy the role name from the SecretKey column on the Cluster Permissions page in the console.
endpoints
Cluster access address. You can obtain the access address from the Access Information module on the Cluster Basic Information page in the console.
consumerGroup
Consumer group name. You can copy the name from the Group Management page in the console.
subscriptions
Topic name. You can copy the name from the Topic Management page in the console.

Step 4: Viewing Message Details

After a message is sent, you will receive a message ID (messageID). You can choose Message Query > General Query in the console to query the recently sent message, including the message details and trace.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan