Appearance
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
Before using the AMQP service, you need to create a SaaS application under the SaaS Development -> SaaS Management menu.
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.
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.)
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.
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
- 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>
- Initialize the SDK
Create an AmqpClient object, storing AccessKey/AccessSecret, connectionUrl, queueName
- 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.
- 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
- Uplink data types corresponding to methods in the HandleMessage object
Method Name | Message Type |
---|---|
upAndDownLine | Online/Offline events |
deviceStatus | Device status |
upLink | Uplink, transparent command uplink |
downLink | Downlink, transparent command downlink |
reqack | ACK confirmation message |
mAttrRead | Downlink, Thing Model property read command issued |
mAttrReadresp | Uplink, Thing Model property read command response |
mAttrWrite | Thing Model property write command issued |
mAttrReport | Uplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model property reporting |
mServInput | Downlink, Thing Model service execution request, corresponding to the Write message type of the transparent data packet protocol |
mServOutput | Uplink, Thing Model service execution response, corresponding to the Event message type of the transparent data packet protocol |
mEventInfo | Uplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model event information reporting |
mEventWarn | Uplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model event warning reporting |
mEventError | Uplink, corresponding to the Event message type of the Thing Model data packet protocol, Thing Model event fault reporting |
locationMode | Set location information sending mode |
locationQuery | Query location information, if empty, returns in the saved MODE |
locationInfoRaw | Response to location information query, active reporting of location information |
locationInfoKV | Response to location information query, active reporting of location information |
enduserUserAdd | End user information change - add |
enduserUserUpdate | End user information change - update |
enduserUserDelete | End user information change - delete |
enduserUserBind | End user device binding information |
productAddAndDel | Product addition/deletion/product authorization information |
productUpdate | Product information change |
deviceModelInfo | Product Thing Model information change |
deviceAddAndDel | Device addition/deletion |
deviceUpdate | Device information modification |
Error Codes
For details, see Error Code Collection