Before you call a TCP SDK to send and subscribe to messages, you must create required resources in the Message Queue for Apache RocketMQ console. You must specify the resource parameters when you call the SDK.
Background information
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 limits
When you use Message Queue for Apache RocketMQ, take note of the following network access limits:
- A topic can be accessed only by a producer or consumer whose group ID is created on the same instance in the same region as the topic. For example, if a topic is created on Instance A in the China (Hangzhou) region, the topic can be accessed only by a producer or consumer whose group ID is created on Instance A in the China (Hangzhou) region.
- If you use an on-premises server and need to access the Message Queue for Apache RocketMQ service over the Internet, you must create a topic and group ID on an instance in
the Internet region.
Producer and consumer clients can be deployed on an on-premises server or an ECS instance in a region. You must make sure that the on-premises server or ECS instance can access the Internet.
For more information about regions, see Regions and zones.
Create an instance
An instance is a virtual machine (VM) resource of Message Queue for Apache RocketMQ. An instance stores the topics and group IDs.
Create a topic
- A topic cannot be used across instances. For example, Topic A created in Instance A is unavailable in Instance B.
- Each topic name must be unique in an instance.
- We recommend that you create different topics to send different types of messages. For example, you can create Topic A for common messages, Topic B for transactional messages, and Topic C for scheduled and delayed messages.
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.
Obtain an endpoint
After you create an instance in the console, you must obtain an endpoint of the instance in the Message Queue for Apache RocketMQ console. To send and subscribe to messages, you must configure the endpoint for the producer and consumer. Then, the producer and consumer can access services in the corresponding instance or region.
After you complete the preceding operations, you can run the sample code and use Message Queue for Apache RocketMQ to send and subscribe to messages.