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.
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.
Step 1: Create resources
- 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)
- Select a region.
Determine the region in which the resources are to be created based on your service needs.
- Login MQTT console.
- In the top navigation bar, select a region, such as china (Beijing) region where you want to create the resources.
- Create Message Queue for MQTTinstance.
First, you create Message Queue for MQTTinstance. Note the following before creating an instance:
Follow these steps to create Message Queue for MQTTinstance:
- 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.
- In the left-side navigation pane, click Overview.
- On the instances page, click create an instance.
- 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.
- 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:
Follow these steps to create and bind a storage instance:
- 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.
- In the left-side navigation pane, choose overview, select the Message Queue for MQTTinstance, click continue configuration.
- 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.
- 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.
- 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).
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.
- 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:
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.
- In the left-side navigation pane, choose message storage.
- In Topic management and select the Message Queue for MQTTinstance, click create Topic.
- 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.
- 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.
- In the left-side navigation pane, click Groups.
- In Group management and select the Message Queue for MQTTinstance, click new Group ID.
- 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.Note
- 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:
- 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.
- In the default display instance details page, select the Message Queue for MQTTinstance name, click instance information tab.
- On the Instance Information tab page, view the domain name of the endpoint in the Endpoint Information section.
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.
- 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.
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.
|MQTT on TCP||SSL||WebSocket||WebSocket SSL/TLS||Flash|
Step 3: Send and subscribe to messages by using an SDK
- 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.
- 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
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:
- In the left-side navigation pane, choose message storage.
- In the Topics list on the Message Storage page, locate the row that contains the created topic and click Send in the Actions column.
- 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.