Before you use a TCP client SDK to send and receive messages, you must create the required resources in the ApsaraMQ for RocketMQ console. When you use the SDK, you must configure the resource parameters based on the resource information.
Before you start
Activate AsparaMQ for RocketMQ and grant permissions to a RAM user
Background information
ApsaraMQ for RocketMQ provides SDKs for multiple programming languages to send and receive messages over the TCP and HTTP protocols. We recommend that you create different groups for different protocols. For information about limits on using groups for each protocol, see Manage groups.
Limits on network access
Before you use ApsaraMQ for RocketMQ, take note of the following limits on network access:
A topic can be accessed by producers or consumers in a group only if the group is created on the same instance and in the same region as the topic. For example, if you create a topic on Instance A in the China (Hangzhou) region, the topic can be accessed only by producers or consumers in a group that is created on Instance A in the China (Hangzhou) region.
Public and private endpoints for TCP and HTTP clients are provided in all regions. In production environments, we recommend that you access ApsaraMQ for RocketMQ in virtual private clouds (VPCs). If you want to access ApsaraMQ for RocketMQ across regions, from on-premises data centers, or over the Internet while Cloud Enterprise Network (CEN) is unavailable, you can use public endpoints to access ApsaraMQ for RocketMQ instances. If you use public endpoints to access ApsaraMQ for RocketMQ instances, you are charged for outbound Internet traffic. For more information, see Billing of Internet traffic.
ApsaraMQ for RocketMQ provides HTTP endpoints and TCP endpoints. Each type of endpoint can be used only by clients of the same protocol type. For example, if you use a TCP client SDK, you can specify only a TCP endpoint in the code.
Create an instance
In ApsaraMQ for RocketMQ, an instance is a virtual machine that is used to store information about topics and groups. To create an ApsaraMQ for RocketMQ instance, perform the following steps:
Log on to the ApsaraMQ for RocketMQ console.
In the left-side navigation pane, click Instances.
In the top navigation bar, select a region, such as China (Hangzhou).
On the Instances page, click Create Instance.
In the Create Message Queue for Apache RocketMQ Instance panel, configure the Instance Type, Name, and Description parameters. Then, click OK.
Create a topic
In ApsaraMQ for RocketMQ, a topic is a first-level identifier that is used to classify messages. For example, you can create a topic named Topic_Trade to identify transactional messages. Then, message producers can publish messages to Topic_Trade and message consumers can subscribe to Topic_Trade to consume the messages. Topics must meet the following requirements:
A topic cannot be used across instances. For example, Topic A that is created on Instance A is unavailable on Instance B.
Each topic name must be unique on an instance.
We recommend that you create different topics to send different types of messages. For example, you can create Topic A for normal messages, Topic B for transactional messages, and Topic C for scheduled and delayed messages.
In the left-side navigation pane of the Instance Details page, click Topics.
On the Topics page, click Create Topic.
In the Create Topic panel, configure the Name and Description parameters, set the Message Type parameter to Normal Message, and then click OK.
NoteIn the following example, normal messages are used. The topic that you create by performing the steps that are described in this section cannot be used to send or receive messages of other types. Each topic can be used to send and receive only messages of a specific type. For information about message types, see Message types.
Create a group
In ApsaraMQ for RocketMQ, a group is used to identify producers or consumers of the same type. Groups must meet the following requirements:
-
Up to 1,000 groups per instance. Reuse or delete unused groups to stay within the limit. To increase this quota, contact ApsaraMQ for RocketMQ technical support.
-
A group cannot be used across instances.
-
ApsaraMQ for RocketMQ supports HTTP and TCP protocols for message consumption. Different groups can use different protocols, but all consumers within the same group should use the same protocol.
-
Mixed protocols within a group may cause consumption failures, message duplication, or message loss.
-
Protocol changes for a group take approximately 1 to 2 hours to take effect.
-
If the actual protocol differs from the one shown in the console, console data may be inaccurate but messaging is unaffected. Contact ApsaraMQ for RocketMQ technical support to update the displayed protocol.
-
-
A group ID is required for each consumer but optional for producers.
In the left-side navigation pane of the Instance Details page, click Groups.
On the Groups page, choose .
In the Create Group for TCP Protocol panel, configure the Group ID and Description parameters. Then, click OK.
Obtain an endpoint
After you create resources in the ApsaraMQ for RocketMQ console, you must obtain the endpoint that you can use to access the instance. Before you send and receive messages, you must specify the endpoint on the producer and consumer clients to allow the producers and consumers to access the instance in the specified region.
In the left-side navigation pane of the Instance Details page, click Instance Details.
In the TCP Endpoint section of the Instance Details page, move the pointer over the endpoint and click the endpoint to copy it.
Before you use endpoints, take note of the following items:
Each type of endpoint can be used only by clients of the same protocol type. For example, if you want to use a TCP client SDK to send and receive messages, you must use the TCP endpoint of your ApsaraMQ for RocketMQ instance to access the ApsaraMQ for RocketMQ broker.
Public and private endpoints for TCP and HTTP clients are provided in all regions. In production environments, we recommend that you access ApsaraMQ for RocketMQ in virtual private clouds (VPCs). If you want to access ApsaraMQ for RocketMQ across regions, from on-premises data centers, or over the Internet while Cloud Enterprise Network (CEN) is unavailable, you can use public endpoints to access ApsaraMQ for RocketMQ instances. If you use public endpoints to access ApsaraMQ for RocketMQ instances, you are charged for outbound Internet traffic. For more information, see Billing of Internet traffic.
After you complete the preceding operations, you can run the sample code and use ApsaraMQ for RocketMQ to send and receive messages.
What to do next
Call TCP client SDKs to send and subscribe to normal messages