Before you call a TCP SDK to send and subscribe to messages, you must create resources in the Message Queue for Apache RocketMQ console. You need to enter the resource information when calling the SDK.
Message Queue for Apache RocketMQ provides SDKs for multiple programming languages to send and subscribe to messages over TCP and HTTP. To use Message Queue for Apache RocketMQ, you must create an instance, a topic, and a group ID. Due to client differences, a group ID cannot be used for both TCP clients and HTTP clients. Therefore, you must create group IDs for TCP clients and HTTP clients separately.
Network access restrictions
When you use Message Queue for Apache RocketMQ, note the following network access restrictions:
- A topic can be accessed only by a producer or consumer with a group ID created on the same instance and the same region as the topic. For example, when a topic is created on instance A in the China (Hangzhou) region, the topic can be accessed only by the producer and consumer with a group ID created on instance A in the China (Hangzhou) region.
- If you want to use Message Queue for Apache RocketMQ over Internet, you can create both the topic and group ID on an instance in the Internet region. Producers and consumers can be deployed on a local server or an ECS instance
in any region, provided that the local server or ECS instance can access the Internet.
For more information about regions, see Regions and zones.
Create an instance
As a virtual machine (VM) resource of Message Queue for Apache RocketMQ, an instance stores the topics and group IDs of messages.
- Log on to the .
- In the top navigation bar, select a region, such as China (Hangzhou).
- In the left-side navigation pane, click Instances.
- On the Instances page, click .
- In the Create Instance dialog box, set Instance Type, Instance Name, and Description, and click OK.
For more information about the billing of Standard Edition and Platinum Edition instances, see t1841146.html#section_6xq_63o_qv3.After the instance is created, it appears on the Instances page.
Create a group ID
- A group ID must be unique within an instance.
- Group IDs and topics implement N:N mapping. A consumer can subscribe to multiple topics and a topic can be subscribed to by multiple consumers. A producer can send messages to multiple topics and a topic can receive messages from multiple producers.
- On the details page of the target instance, click Groups in the left-side navigation pane.
- On the Groups page, choose .
- In the Create Group ID dialog box, set Group ID and Description, and click OK.
After the group ID is created, it appears in the group ID list.
Create a topic
- Topics cannot be used across instances. For example, Topic A created in Instance A cannot be used in Instance B.
- A topic name must be unique within an instance.
- We recommend that you create different topics to send different types of messages. For example, create Topic A for normal messages, Topic B for transactional messages, and Topic C for scheduled and delayed messages.
- On the details page of the target instance, choose from the left-side navigation pane.
- In the Create Topic dialog box, set Topic, select Normal Message for Message Type, enter Description, and click OK.
For more information about message types, see Message types.After the topic is created, it appears in the topic list.
After creating resources in the console, you need to obtain the endpoint of the instance in the console. To access services in an instance or a region when sending or subscribing to messages, you need to configure the endpoints for the producer and consumer.
- On the details page of the target instance, click Instance Details in the left-side navigation pane.
- On the Instance Information tab page that appears by default, find the TCP Endpoint section, and click the target TCP endpoint to copy it.
Note HTTP and TCP endpoints cannot be used interchangeably.
- The endpoint displayed in the console is the endpoint of a specific instance in a region. Different instances in the same region have different endpoints.
- Only the instances in the Internet region have public TCP endpoints. Instances in other regions only have internal TCP endpoints.
- TCP endpoints cannot be used across regions. For more information, see Configure the TCP internal endpoint.
After completing the preceding preparations, you can run the sample code and use Message Queue for Apache RocketMQ to send and subscribe to messages.