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 can be created on an ApsaraMQ for RocketMQ instance. We recommend that you reuse groups or delete groups that are no longer required at the earliest opportunity. If you want to increase the upper limit on groups, contact ApsaraMQ for RocketMQ technical support.
-
A group cannot be used across instances. For example, a group that is created on Instance A cannot be used on Instance B.
-
In ApsaraMQ for RocketMQ, consumers can consume messages over the HTTP or TCP protocol. Different consumer groups can use different protocols. We recommend that you specify the same protocol for all consumers in a group.
-
If consumers in the same group consume messages over different protocols, message consumption may fail and message duplication or message loss may occur.
-
Approximately 1 to 2 hours is required to change the protocol over which consumers in a group consume messages.
-
If consumers in a group consume messages over a protocol that is different from the protocol displayed in the ApsaraMQ for RocketMQ console, the data displayed in the console can be inaccurate. This does not affect the messaging of the group. In this case, you can contact ApsaraMQ for RocketMQ technical support to change the protocol displayed in the console to the protocol that is used by consumers in the group.
-
-
A group ID must be specified for each consumer. You do not need to specify a group ID for each producer.
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