Step 2: Create resouces

Last Updated: Apr 08, 2018

In the MQ system, a producer sends messages to a specified Topic, and a consumer obtains and consumes messages after subscribed to the that Topic.

For your applications to access MQ, you need to create related MQ resources first, including:

Note: Once you have deleted the resources, such as the Topics, the producer IDs and the consumer IDs, their related resources will also be cleared within 10 minutes.

Create a Topic

Topic is the primary classification of messages in MQ, for example, you can create a Topic named “Topic_Trade” for the trade related messages. The first step of using MQ is to create Topics for your application.

You can create a Topic by following the steps below:

  1. Log on to MQ Console to enter the Topics page by default.

  2. Select a region (such as Public Network region), and then click Create Topic.

    Note:

    • For testing purposes or local (non-Alibaba Cloud ECS instance ) usage of the MQ service, please create your Topics in the public network environment. The producers and the consumers can be deployed locally or deployed on an ECS instance in any region on the premise that the local servers or the corresponding ECS instances can access the public network.
    • To use the MQ service in a production environment, you must deploy your application on an ECS instance, and create the Topics in the region where the application is located, that is the region where the corresponding ECS instance is located.
    • A Topic cannot be used cross regions. For example, if a Topic is created in “North China 2,”, both the message producer and consumer must also be running on an ECS instance in “North China 2.”
    • For detailed information about regions, see Regions and Zones in the ECS documentation.
  3. In the Create Topic dialog box, enter a Topic name and a remark, and click OK, and the topic you just created will appear in the Topic list.

    Note: The Topic name must be globally unique. If a name is already used by another user, you are not able to create a Topic with that name any more.

Message type

There are the following several types of messages:

  • Unordered messages: The First-In-First-Out (FIFO) order is not guaranteed; include normal messages, scheduled/delayed messages and transactional messages. We recommend that you create different Topics to send different types of messages, for example, to create Topic A for normal messages, Topic B for transactional messages, and Topic C for scheduled/delayed messages.
  • Globally ordered massage: All messages are produced and consumed in strict FIFO order.
  • Partitionally ordered messages: Messages are partitioned by sharding keys, so as to improve overall concurrency and performance. Messages in the same partition are produced and consumed in strict FIFO order.

Create a Producer ID

Once you have created a Topic, you then need to create the resource for message production for the Topic, that is, to create a Producer ID. One Topic can only correspond to one Producer ID.

To create a Producer ID for your Topic, follow the steps below:

  1. On the left-side navigation pane in the MQ console, Select Topics.

  2. On the Topics page, locate the Topic you just created, and click Create Producer in the Actions column.

  3. On the Create Producer page, enter a Producer ID, and click OK.

    Note:

    • The Producer ID must be globally unique. If a name already exists, you are not able to create a Producer ID with that name any more.
    • A Topic and its producer must be located in the same region, for example, if you have created “Topic_open” in the “Public Network,” region, then the Producer ID for “Topic_open” must also be located in the “Public Network.” region.
    • The relationship between Producer ID and Topic is 1:N; that is, one Topic can only be bound with one Producer ID, while one Producer ID can be bound with multiple topics.

Create a Consumer ID

Once you have created the message producer, you need to create the resource for message consumption for the Topic, that is, to create Consumer IDs.

To create a Consumer ID, follow the steps below:

  1. On the left-side navigation pane in the MQ console, Select Topics.

  2. On the Topics page, locate the Topic you just created, and click Create Consumer in the Actions column.

  3. On the Create Consumer page, and click OK.

    Note:

    • The Consumer ID must be globally unique. If a name already exists, you are not able to create a Consumer ID with that name any more.
    • A Consumer ID and its corresponding Topic must located in the same region, for example, “Topic_open” in the “Public Network” region can be bound with the Consumer ID “CID_123,” which is also located in the “Public Network” region, but “Topic_huabei1” in the “North China 1” region cannot be bound with this Consumer ID.
    • The relationship between Consumer ID and Topic is N:N. One Consumer ID can subscribe to multiple Topics, and one Topic can correspond to multiple Consumer IDs.

Create Alibaba Cloud AccessKey and SecretKey

When using SDK/API to send and subscribe to messages, you not only need to specify the Topic, Producer ID, and consumer ID, but also need to enter your identity verification information that you have created in the RAM console, that is, the Access Key ID and Access Key Secret.

Please refer to Create AccessKey on how to create AccessKey and SecrectKey.

Once the above preparation is done, you can run sample code and use MQ to send and subscribe to messages.

Thank you! We've received your feedback.