This topic provides a quick start guide to using and getting familiar with product features. Message Queue for MQTTTo send and receive messages over the MQTT protocol that is supported by default,

For access over non-MQTT protocols, such as new energy sources, you must first purchase new energy sources. Message Queue for MQTTEnterprise Platinum Edition, and enjoy the corresponding documentation and technical support services through the exclusive channel.


Message Queue for MQTTAliwareMQ for IoT must be used with backend MQ.

  • Message Queue for MQTTAn MQTT instance is a stateless gateway instance that is used to maintain client connections and to forward messages in mobile Internet and IoT scenarios. It does not support message data persistence. Therefore, you must configure a message storage instance for message storage and message data persistence.
  • At this stage, each Message Queue for MQTTthe instance (Gateway instance) must be bound to a storage instance (Message Queue instance). Non-persistent usage (in direct push mode, where messages are not persistent) will be available in the future.
  • Currently, the message storage instance only supports Message Queue for Apache RocketMQtype of backend storage instance, which will be supported in the future. Message Queue for Apache KafkaAnd (RabbitMQ) and other types of storage instances.
  • Currently, you can create a limited number of Message Queue for MQTTinstance, and one Message Queue for MQTTan instance can only be bound to a single corresponding Message Queue for Apache RocketMQinstance. For the maximum number of instances that can be created in one region, see the console prompts.

When you use Message Queue for MQTT, note the following network access restrictions:

Only the topics and Group IDs in the same instance in the same region can communicate with each other. For example, a Topic is created china (Beijing) instance A, then this Topic can be accessed only china (Beijing) corresponding to the Group ID created in instance A in the region Message Queue for MQTTclient Access.


Figure 1 Shows how to use the Message Queue for MQTTthe process of sending and receiving messages.

Figure 1. Quick start process
Flowchart for an ApsaraDB for Redis instance

Ru Figure 1as shown in the following figure, you need to create resources before sending and receiving messages on a client. Otherwise, Message Queue for MQTTthe server rejects the connection with an invalid Client ID.


  • You have activated the parent MQ service. If not, activate this service.
  • You have an Alibaba Cloud AccessKey. For more information, see Create an AccessKey.

Step 1: Create resources

The resources include:
  • Message Queue for MQTTInstance (for maintaining client connections and forwarding messages)
  • Message storage instance (for message storage, currently only Message Queue for Apache RocketMQinstance)
  • Topic (level-1 topic for message sending and subscription, that is, the parent topic)
  • Group ID (for client identification)
  1. Select a region.

    Determine the region in which the resources are to be created based on your service needs.

    1. Login MQTT console.
    2. In the top navigation bar, select a region, such as china (Beijing) region where you want to create the resources.
  2. Create Message Queue for MQTTinstance.
    First, you create Message Queue for MQTTinstance. Note the following before creating an instance:
    • You can create a limited number of instances in each region. For more information, see the console prompts.
    • Estimate the TPS, number of connections, and number of subscriptions based on the service scenario. Select the appropriate instance specifications. For subscription instances, if you select an excessively small specification, rate limiting and throttling may be triggered and your services may be affected. Pay-As-You-Go instances also have a threshold that is set by default. If the threshold is exceeded, you need to submit a ticket for allocation. For the specific thresholds, see the default alarm levels of the instance.
    • A Standard Edition instance takes effect upon purchase. An Enterprise Platinum Edition instance takes time to deploy and you will be notified when the instance is available.
    Follow these steps to create Message Queue for MQTTinstance:
    1. In the left-side navigation pane, click Overview.
    2. On the instances page, click create an instance.
    3. On the purchase page, select Message Queue for MQTTinstance version and the corresponding configuration, and then follow the instructions on the page to complete the purchase.

    Return to the console overview page, you can see the purchased (created) Message Queue for MQTTinstance.

  3. Create and bind a data storage instance.

    Finish creating Message Queue for MQTTyou must create an instance to store topics and messages. (currently, only Message Queue for Apache RocketMQinstance), and then create an Message Queue for Apache RocketMQinstance and Message Queue for MQTTone-to-one binding to ECS instances.

    The binding has the following limits:
    • A Message Queue for MQTTthe instance can be bound only once, and cannot be changed after the binding is successful.
    • Each storage instance can be bound to only one Message Queue for MQTTinstance, one-to-many binding is not allowed.
    • The two instances to be bound must have the same namespace type. That is, an instance with an exclusive namespace cannot be bound to an instance with a non-exclusive namespace.
    • If you delete the Message Queue for MQTTthe storage instance bound to the instance, Message Queue for MQTTthe instance becomes unavailable.
    Follow these steps to create and bind a storage instance:
    1. In the left-side navigation pane, choose overview, select the Message Queue for MQTTinstance, click continue configuration.
    2. In configure message persistence dialog box appears, select options based on the instance and your requirements.
      • If you have already purchased Message Queue for Apache RocketMQinstance, please select select an existing instance. A list of message storage instances that you have created (purchased) is displayed. Then, click Message Queue for Apache RocketMQmessage storage instance, and then click confirm complete the binding.
        Figure 2. Select an existing instance
        Select an existing instance
      • If you have not purchased Message Queue for Apache RocketMQinstance, select the following options:
        • Create a shared instance: create Message Queue for Apache RocketMQstandard Edition instance. Enter a name and description for the instance, and then click confirm to complete the creation.
          Figure 3. Create a shared instance
          Create a shared instance
        • Purchase an enterprise Platinum Edition instance: create Message Queue for Apache RocketMQenterprise Platinum Edition instances. Select purchase an enterprise Platinum Edition instance, click go to purchase now, and follow the prompts on the page to complete the purchase (that is, create).
          Figure 4. Create a Platinum Edition instance
          Create a Platinum Edition instance

        After creating, repeat steps i and ii, and select select an existing instance. Click the created Message Queue for Apache RocketMQinstance, and then click confirm complete the binding.

  4. You can call this operation to create a topic.

    To send and receive messages over MQTT, you must create an MQTT parent topic. Subtopics at different levels can be directly used in code without the need to create them.

    Message Queue for MQTTA one-to-one binding relationship is established between the MQTT instance and the storage instance. Therefore, the Topic is actually created on the storage instance. Message Queue for MQTTThe console performs all Topic operations based on the habits of storage instances.

    If you have been using Message Queue for Apache RocketMQyou can directly use a Topic if you have created one before. If you have not created any topics, perform the following steps:

    1. In the left-side navigation pane, choose message storage.
    2. In Topic management and select the Message Queue for MQTTinstance, click create Topic.
      Figure 5. Create a topic
      Create a topic
    3. In the Create Topic dialog box, enter a topic name, select the message type of the topic for message storage, sending, and receiving, and enter remarks. Then, click OK.
    Note If you want to use Message Queue for MQTTTo send ordered messages by the client, select the ordered message type. However, Message Queue for MQTTcurrently, consumption scenarios on the client do not support strong order.
  5. Create a Group ID.

    Message Queue for MQTTA group ID specifies the name of a group of nodes with identical logic and functions, representing a category of devices with the same functions. The group ID and device ID are used together to identify the client ID of an MQTT client. For more information, see Terms.

    1. In the left-side navigation pane, click Groups.
    2. In Group management and select the Message Queue for MQTTinstance, click new Group ID.
      Figure 6. Create a group ID
      Create a group ID
    3. In the Create Group ID dialog box, enter a group ID and click OK.

    The group ID appears on the Groups page after being created. The Groups page shows all your group IDs in the current region.

    • Delete the group ID in a timely manner if it is no longer needed.
    • A group ID can only be used by the account that created it. A group ID that is created by the primary account cannot be used by a sub-account. The sub-account must create its own group IDs separately.

Step 2: Obtain an endpoint

This parameter is required when you use an SDK to send and subscribe to messages. Message Queue for MQTTThe access point of the instance. Message Queue for MQTTAn instance endpoint consists of the instance domain and port.

In Message Queue for MQTTinstance and Message Queue for Apache RocketMQafter the instance is bound, the endpoint information is displayed in the queries access point information. Area, you can directly get the access point information.

Binding successfully Message Queue for MQTTinstance and Message Queue for Apache RocketMQyou can also perform the following steps to obtain the endpoint after the instance is deployed:

  1. In the top navigation bar of the console, select the region where the created resource is located. Then, in the left-side navigation pane, click instance details.
  2. In the default display instance details page, select the Message Queue for MQTTinstance name, click instance information tab.
  3. On the Instance Information tab page, view the domain name of the endpoint in the Endpoint Information section.
    Figure 7. Obtain the endpoint
    Retrieve MNS endpoints

Message Queue for MQTTAlso provides public endpoint, classic Network Access Point and VPC access point. We recommend that you use public endpoints for clients in IoT and mobile Internet scenarios. Classic network and VPC endpoints are for use only in some special scenarios. In general, we recommend that you use an MQ service in cloud server scenarios, such as Message Queue for Apache RocketMQimplementation.

Note To connect to the service with an endpoint on a client, use the domain name rather than the IP address because the IP address can change at any time. Problems in the following use cases Message Queue for MQTTthe product Party is not responsible for:
  • The client uses the IP address instead of the domain name for access. As a result, the original IP address becomes invalid.
  • After you set up a network firewall policy for IP addresses in client networks, the new IP addresses will be blocked by the firewall policy.

Port Number

Currently Message Queue for MQTTsupports MQTT SSL, WebSocket, WebSocket SSL/TLS, and Flash in addition to the standard MQTT on TCP. The corresponding service ports are listed in Table 1. Replace the port number in an endpoint as required.

Note Message Queue for MQTTCurrently, one-way SSL encryption is provided, so you do not need the client to upload the certificate. In addition, the certificate of the server is automatically delivered along with the request handshake and is strongly bound to the endpoint domain name. Therefore, custom certificate encryption is not supported currently.
Table 1. Port description
MQTT on TCP SSL WebSocket WebSocket SSL/TLS Flash
1883 8883 80 443 843

Step 3: Send and subscribe to messages by using an SDK

  1. Download the client SDK. For the download addresses of SDKs in different languages, see Download the SDK.

    Due to Message Queue for MQTTsupports the standard MQTT protocol by default, so we recommend that you use open source third-party client SDKs. If a client SDK in a desired language is not listed, search for MQTT-compatible SDKs on the Internet.

  2. Download the Demo project, view the corresponding parameter descriptions, and then you can run the Demo to send and subscribe to messages. Demo download address, see Demo project.

    The current demo library only covers some mainstream languages and will be updated later. If the corresponding development language is not covered, download a Java Demo for modification. The Demo project only demonstrates basic functions. You must modify all the parameters before using them in the actual online environment.


In addition to sending messages by using an SDK or API, you can send messages in the console to quickly verify the availability of the topic. The procedure is as follows:

  1. In the left-side navigation pane, choose message storage.
  2. In the Topics list on the Message Storage page, locate the row that contains the created topic and click Send in the Actions column.
    Figure 8. Sends messages.
    Sends messages.
  3. In the Send Message dialog box, set the message attributes, enter the message content, and click OK.

    The console returns a notification that the message has been sent successfully and the corresponding message ID.