Before you use a TCP client SDK to send and subscribe to messages, create the required resources in the Message Queue for Apache RocketMQ console. You must configure the resource parameters before you call the SDK.

Background information

Message Queue for Apache RocketMQ provides client SDKs for multiple programming languages. Different SDKs are provided to send or subscribe to messages over different protocols, including TCP and HTTP. We recommend that you create different group IDs for different protocols. For more information about the limits on using groups for each protocol, see Group management.

Network access limits

Before you use Message Queue for Apache RocketMQ, take note of the following network access limits:

  • A topic can be accessed by a producer or a consumer only if the group of the producer or consumer and the topic are created on the same instance. 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 is created on Instance A in the China (Hangzhou) region.
  • If you use a local server and want to connect to Message Queue for Apache RocketMQ over the Internet, you must create a topic and a group on an instance in the Internet region. Region

    Producer and consumer clients can be deployed on a local server or an Elastic Compute Service (ECS) instance that can access the Internet.

    For more information about regions, see Regions and zones.

Create an instance

An instance is a virtual machine that provides the Message Queue for Apache RocketMQ service. An instance stores topics and group IDs.

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

    For more information about the billing of the Standard Edition and Enterprise Platinum Edition instances, see Overview.

    After the instance is created, the instance is displayed on the Instances page.

Create a topic

A topic is a first-level identifier that is used to classify messages in Message Queue for Apache RocketMQ. For example, you can create a topic named Topic_Trade for transactional messages. Message producers send messages to Topic_Trade. Message consumers 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 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 normal messages, Topic B for transactional messages, and Topic C for scheduled and delayed messages.
  1. On the details page of the instance, click Topics in the left-side navigation pane.
  2. On the Topics page, click Create Topic.
  3. In the Create Topic panel, configure the Name and Description parameters, set Message Type to Normal Message, and then click OK.
    Create a topic
    Note In the following example, normal messages are used. The topics that you create by following the procedure that is described in this section cannot be used to send or subscribe to other types of messages. Each topic can be used to send or subscribe to messages of a specific type. For more information about message types, see Message types.
    The topic that you created appears in the topic list and the value of the Status parameter for the topic is Enabled.
    Note If the value of the Status parameter for the topic is Creating, refresh the page until the status of the topic changes to Enabled. After the topic is changed, you can use the topic.

Create a group ID

You can create a group ID to identify producers or consumers of the same type. Group IDs must meet the following requirements:
  • Each group can be used in only one instance. For example, a group that is created in Instance A cannot be used in Instance B.
  • In Message Queue for Apache RocketMQ, consumer groups can consume messages over HTTP or TCP. Different consumer groups can use different protocols. We recommend that you create a group for each protocol.
    • If multiple consumers with the same group ID use different protocols, message consumption may fail, and message duplication and message loss may occur.
    • Approximately 1 to 2 hours is required to change the protocol that is used by the consumers in a group.
    • If the consumers in a group consume messages by using a protocol that is different from the protocol that is displayed in the console, the data that is displayed in the console can be inaccurate. This does not affect messaging of the group. You can submit a ticket to change the protocol that is displayed in the console to the protocol that is being used.
  • A group ID must be specified for each consumer. You do not need to specify a group ID for each producer.
  1. On the details page of the instance, click Groups in the left-side navigation pane.
  2. On the Groups page, choose TCP > Create Group.
  3. In the Create Group for TCP Protocol panel, configure the Group ID and Description parameters and click OK.
    create_group_id
    The group ID that you created appears in the group ID list.

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 or subscribe to messages, configure the endpoint on the producer or consumer to allow the producer or consumer to access the instance in a specific region.

  1. On the details page of the instance, click Instance Details in the left-side navigation pane.
  2. On the Instance Details page, click the Endpoints tab.
  3. In the TCP Endpoint section, move the pointer over the endpoint and click the endpoint to copy the endpoint.
    tcp_endpoint
    The following list describes the limits on using the endpoint:
    • The TCP endpoint that is displayed in the console is the endpoint of a specific instance in a region. Different instances in the same region use different endpoints.
    • Only the instances in the Internet region use public TCP endpoints. Instances in other regions use only private TCP endpoints.
    • TCP endpoints cannot be used across regions. For more information, see Announcement on the settings of internal TCP endpoints.
    Note The HTTP endpoint and TCP endpoint of the same instance cannot be interchangeably used.

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.

What to do next

Call TCP client SDKs to send and subscribe to standard messages