Skip to content

AMQP SDK Integration Example

AMQP is mainly used for SaaS system integration, enabling SaaS applications to receive device uplink data in real-time. Quick integration can be achieved through the SDK.

Prerequisites

  1. Before using the AMQP service, you need to create a SaaS application under the SaaS Development -> SaaS Management menu.

  2. Create or use an existing queue in the SaaS Details -> Message Subscription -> Queue List page, and obtain the queue name, which will be needed as a parameter for SDK initialization.

  3. Create a product-level subscription in the SaaS Details -> Message Subscription -> Subscription List page, and configure the event types that need to be pushed as needed. (Note: Different data levels can subscribe to different event types.)

  4. If you need to manage message subscription features through the SaaS application, please activate and authorize the message subscription service package in the SaaS Details -> Service page.

  5. Obtain the AccessKey and AccessSecret, which will be needed as parameters for SDK initialization.

Development Environment Preparation

The development environment used in this example is as follows:

● Operating System: Windows10
● JDK Version: JDK8
● Integrated Development Environment: IntelliJ IDEA Community Edition

SDK Example

  1. Download the jar package, in this example we use Maven reference:
<dependency>
    <groupId>com.quectel.aiot</groupId>
    <artifactId>quecloud-sdk-dev-msg</artifactId>
    <version>1.9.0.RELEASE</version>
</dependency>
  1. Initialize the SDK

Create an AmqpClient object, storing AccessKey/AccessSecret, connectionUrl, queueName

  1. Call steps:

a) Complete SDK initialization. Get the corresponding AmqpClient object

b) Call the start method of the AmqpClient object to begin connecting to RabbitMQ and receiving messages.

The SDK provides two ways to process received messages. First, through the DeliverCallback class to customize message processing. Second, by implementing HandleMessage. Each method in HandleMessage corresponds to a type of uplink data, such as device online/offline, ACK confirmation messages, etc.

  1. Code example
public void msgUpLinkDemo(){
    AmqpClient amqpClient = new AmqpClient("${accessKey}","${accessSecret}","${connectionUrl}","${queueName}");
    HandleMessage handleMessage = new HandleMessageImpl();
    amqpClient.start(handleMessage);
}

For detailed demo code, see GitHub:

https://github.com/thridparty-cloud2/quecloud-sdk-dev-msg-demonstration.git

  1. Uplink data types corresponding to methods in the HandleMessage object
Method NameMessage Type
upAndDownLineOnline/Offline events
deviceStatusDevice status
upLinkUplink, transparent command uplink
downLinkDownlink, transparent command downlink
reqackACK confirmation message
mAttrReadDownlink, Thing Model property read command issued
mAttrReadrespUplink, Thing Model property read command response
mAttrWriteThing Model property write command issued
mAttrReportUplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model property reporting
mServInputDownlink, Thing Model service execution request, corresponding to the Write message type of the transparent data packet protocol
mServOutputUplink, Thing Model service execution response, corresponding to the Event message type of the transparent data packet protocol
mEventInfoUplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model event information reporting
mEventWarnUplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model event warning reporting
mEventErrorUplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model event fault reporting
locationModeSet location information sending mode
locationQueryQuery location information, if empty, returns in the saved MODE
locationInfoRawResponse to location information query, active reporting of location information
locationInfoKVResponse to location information query, active reporting of location information
enduserUserAddEnd user information change - add
enduserUserUpdateEnd user information change - update
enduserUserDeleteEnd user information change - delete
enduserUserBindEnd user device binding information
productAddAndDelProduct addition/deletion/product authorization information
productUpdateProduct information change
deviceModelInfoProduct Thing Model information change
deviceAddAndDelDevice addition/deletion
deviceUpdateDevice information modification

Error Codes

For details, see Error Code Collection