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.

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 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.

  1. Log on to the Message Queue for Apache RocketMQ console.
  2. In the top navigation bar, select a region, such as China (Hangzhou).
  3. In the left-side navigation pane, click Instances.
  4. On the Instances page, click create_icon.
  5. In the Create Instance dialog box, set Instance Type, Instance Name, and Description, and click OK.
    create-instance

    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

After you have created an instance and a topic, you need to create a group ID for the message consumer or producer.
  • 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.
Note A group ID is required for consumers but is optional for producers.
  1. On the details page of the target instance, click Groups in the left-side navigation pane.
  2. On the Groups page, choose TCP > Create Group ID.
  3. In the Create Group ID dialog box, set Group ID and Description, and click OK.
    create-GID
    After the group ID is created, it appears in the group ID list.

Create a topic

A topic is the first-level identifier for classifying messages in Message Queue for Apache RocketMQ. For example, you can create a topic named Topic_Trade for transactional messages. The message producer sends messages to Topic_Trade and the message consumer subscribes to Topic_Trade to consume messages.
  • 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.
  1. On the details page of the target instance, choose Topics > Create Topic from the left-side navigation pane.
  2. In the Create Topic dialog box, set Topic, select Normal Message for Message Type, enter Description, and click OK.
    create-topicFor more information about message types, see Message types.
    After the topic is created, it appears in the topic list.

Obtain endpoints

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.

  1. On the details page of the target instance, click Instance Details in the left-side navigation pane.
  2. On the Instance Information tab page that appears by default, find the TCP Endpoint section, and click the target TCP endpoint to copy it.
    TCP-endpoint
    • 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.
    Note HTTP and TCP endpoints cannot be used interchangeably.

After completing the preceding preparations, you can run the sample code and use Message Queue for Apache RocketMQ to send and subscribe to messages.

What to do next

Call TCP SDKs to send and subscribe to messages