After a device is connected to IoT Platform, the device submits data to IoT Platform. Then, the data can be forwarded to your server by using the Advanced Message Queuing Protocol (AMQP). This article describes how to configure an AMQP server-side subscription. Your server can receive data from the street lamp by using an AMQP client.

Background information

The following figure shows the process of obtaining device messages by configuring an AMQP server-side subscription. AMQP


  1. Log on to the IoT Platform console.
  2. On the Instance Overview page, click Public Instance.
    Notice Enterprise Edition instances are available only in the China (shanghai) and Japan (Tokyo) region. If your IoT Platform is not activated in the China (shanghai) or Japan (Tokyo) region, skip this step.
  3. Configure a consumer group to consume messages. Your server can obtain the messages by listening to the consumer group.
    1. In the left-side navigation pane, choose Rules > Server-side Subscription and click the Consumer Groups tab.
    2. Click Create Consumer Group.
    3. In the Create Consumer Group dialog box, set the consumer group name to StreetLampConsumerGroup and click OK.
  4. Configure the server-side subscription for the product to which the street lamp device belongs. This allows your server to subscribe to various types of messages under the product.
    1. In the left-side navigation pane, choose Rules > Server-side Subscription.
    2. On the Subscriptions tab of the Server-side Subscription page, click Create Subscription.
    3. In the Create Subscription dialog box, set the parameters and click OK.
      Power bank cabinet-Create Subscription
      Parameter Description
      Products Select StreetLamp.
      Subscription Type Select AMQP.
      Consumer Group Select StreetLampConsumerGroup that is created in the previous step.
      Message Type Select Device Upstream Notification.
  5. Connect the AMQP client with IoT Platform.
    In this example, Java is used for development. We recommend that you use the Apache Qpid JMS client. To download the client and view the instructions, see Qpid JMS 0.57.0.

    In this example, the development environment consists of the following components:

    To connect the AMQP client to IoT Platform, perform the following steps:
    1. Download the demo package and decompress it.
    2. Open IntelliJ IDEA and import the sample project aiot-java-demo in the demo package.
    3. In the file under the src/main/java/com.aliyun.iotx.demo directory, set the parameters to connect the JMS client with IoT Platform. The following table describes the parameters.
      Parameter Example Description
      accessKey LTAI4GFGQvKuqHJhFa****** Log on to the IoT Platform console, move the pointer over the profile picture, and then click AccessKey Management to obtain the AccessKey ID and AccessKey secret.
      Note If you use a RAM user, you must attach the AliyunIOTFullAccess permission policy to the user. This policy allows the user to manage IoT Platform resources. Otherwise, the connection with IoT Platform fails. For more information about how to authorize a RAM user, see RAM user access.
      accessSecret iMS8ZhCDdfJbCMeA005sieKe******
      consumerGroupId VWhGZ2QnP7kxWpeSSjt****** The ID of the consumer group that is created in Step 3. You can view the ID on the Public Instance page of the IoT Platform console. Choose Rules > Server-side Subscription, and then click the Consumer Groups tab. Find the consumer group and obtain the ID.
      • Example for a public instance of the new version: iot-w3***
      • Example for a public instance of the new version: ""
      The ID of the instance.
      • If you use a public instance of the new version, obtain the instance ID on the Overview page. Find the Public Instance section and view the ID.
      • If you use a public instance of the previous version, enter a null value. No instance ID exists.
      clientId 12345 The ID of the client. We recommend that you use a unique identifier, such as the UUID, MAC address, or IP address of the client. The client ID must be 1 to 64 characters in length.

      Log on to the IoT Platform console and click the card of the instance that you want to manage. Choose Rules Engine > Server-side Subscription > Consumer Groups. Find the consumer group that you want to manage and click View in the Actions column. The ID of each client is displayed on the Consumer Group Details page. You can use client IDs to efficiently identify clients.

      connectionCount 4 The number of connections that are enabled on the AMQP client. Maximum value: 64. This parameter is used for scale-out in real-time message pushing scenarios.

      On the Consumer Group Details page, each connected client is displayed in the format of ${clientId}+"-"+ a number. The minimum number is 0.

      • Example for a public instance of the new version: iot-***
      • Example for a public instance of the previous version: 198426864******
      The AMQP endpoint, see View the endpoint of an instance.
    4. After you run the sample code, the following log data is returned. The data indicates that the AMQP client is connected to IoT Platform and can receive messages.
      Note In this example, the Thread.sleep(60 * 1000); code snippet is added to end the program after the program starts and runs for 1 minute. You can set the running time based on your business requirements.
      Running result
For more information about how to configure a server-side subscription to receive device messages, see the following articles: