Server-side development

Updated at:
Copy as MD

After you complete device-side development, you can develop the server side to receive device data from IoT Platform. This topic uses a Java example to demonstrate the process for a server to receive device data.

Prepare the development environment

This topic uses the following Java development environment:

Receive device data on the server

The server receives messages through an AMQP client. You can configure the AMQP client to connect to IoT Platform and listen for device messages. For more information, see AMQP client connection guide and Java SDK connection example.

This example uses the Java development language and the Apache Qpid JMS client. For instructions on how to use the Qpid JMS client, see the Qpid JMS 0.57.0 documentation.

Follow these steps to develop the AMQP client.

  1. Download the demo code package and unzip it.

  2. Open IntelliJ IDEA and import the amqp-demo project from the demo package.

    The pom.xml file already contains the Maven dependency to download the Qpid JMS client.

  3. In the AmqpClient.java file, located in the src/main/java/com.aliyun.iotx.demo directory, modify the parameters to connect the JMS client to IoT Platform as described in the following table.

    private final static Logger logger = LoggerFactory.getLogger(AmqpClient.class);
    private static String accessKey = "${YourAccessKey}";
    private static String accessSecret = "${YourAccessSecret}";
    private static String consumerGroupId = "${YourConsumerGroupId}";
    
    // iotInstanceId: The instance ID.
    private static String iotInstanceId = "${YourIotInstanceId}";
    
    // The console displays the clientId on the consumer group status page for server-side subscriptions.
    // Use a unique identifier, such as a machine UUID, MAC address, or IP address, as the clientId. This helps you distinguish between different clients.
    private static String clientId = "${YourClientId}";
    
    // ${YourHost} is the connection domain name. For more information, see the AMQP client connection guide.
    private static String host = "${YourHost}";
    
    // Specify the number of connections to start for a single process.
    // The consumption rate of a single connection is limited. For more information, see Limits. The maximum number of connections is 128.
    // The number of connections is related to the consumption rate and rebalancing. Add one connection for every 500 QPS.
    private static int connectionCount = 4;

    Parameter

    Example

    Description

    accessKey

    LTAI****

    The AccessKey ID and AccessKey secret of the Alibaba Cloud account or its RAM user.

    Log on to the IoT Platform console, move the pointer over the profile picture in the upper-right corner, and then click AccessKey Management to obtain the AccessKey ID and AccessKey secret.

    accessSecret

    ********

    consumerGroupId

    VWhGZ2QnP7kxWpeSSjt******

    The ID of the handheld thermometer data consumer group that you created. For more information, see Step 6 in Configure cloud-side development.

    iotInstanceId

    "iot-cn-6ja***"

    The ID of the instance to which the device belongs.

    In the console, you can view this on the Instance Overview page.

    • If an ID exists, enter the ID.

    • If no ID exists, enter an empty value, such as iotInstanceId = "".

    clientId

    12345

    The client ID. You can customize it. The length cannot exceed 64 characters. Set it to a unique identifier of the server where the AMQP client is located, such as a UUID, MAC address, or IP address. This helps you identify and distinguish different clients.

    After the AMQP client is connected, this parameter is displayed on the details page of the handheld thermometer data consumer group in the console.

    connectionCount

    4

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

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

    host

    iot-***.amqp.iothub.aliyuncs.com

    The AMQP connection domain name. For more information, see View and configure instance endpoint information (Endpoint).

What to do next

End-to-end testing