The previous article mainly introduces the WEBsocket interface of TB transparent transmission, into the format required by the business. The previous article covered how to pass through TB’s REST interface to a standard format. Based on the above two articles belong to the transformation ability of single interface, this article will introduce how to aggregate multiple interfaces of TB to meet complex business scenarios.
Question:
Requirement: Query all devices in an asset (the output parameter should contain the device name, device description, and device status).
Analysis: The request parameter must be the asset ID. Check the API of the TB platform and find that only the ids of all devices contained in the asset can be obtained based on the asset ID. That is, only the relationship between assets and devices can be obtained. To obtain device details (device name, device description, etc.), you need device-related APIS. Of course, TB provides an interface to obtain device details based on the device ID. This is where the aggregation interface comes in. I have described the powerful functions of the Kettle platform before. Kettle is good at data aggregation of multiple data sources and data protocol and format conversion. It is obviously very suitable for solving such problems. The following are TB-related interfaces (relational interfaces and device interfaces)
Solution:
The kettle platform is used. The following figure shows the kettle conversion file prepared.
Viewing the REST Client node, you will find that the RELATIONSHIP interface of TB is invoked to query the relationship between assets and devices based on the asset ID.
View “resolve result interface”, is through JS to call TB’s device details interface to achieve, and finally encapsulate the data into a standard JSON format.
Upload the kettle conversion file to the Kettle platform and test it.
The final output is as follows:
{ "success":true, "resultCode":"00", "resultMsg":"", "result":[ { "name":"1_G03", "Id" : "53858 the b20-8554-11 eb - BCCD - c11a74ecd150", "nickname" : "outlet ark", "note" : "outlet ark"}, {" name ":" 1 _g02 ", "Id" : "5386 eab0 eb - 8554-11 - BCCD - c11a74ecd150", "nickname" : "the power metering tank", "note" : "the power metering tank"}, {" name ":" 1 _g01 ", "Id" : "53884 a40-8554-11 eb - BCCD - c11a74ecd150", "nickname" : "the power into the line", "note" : "the power into the line"}, {" name ":" 1 _g05 ", "Id" : "538 a4610 eb - 8554-11 - BCCD - c11a74ecd150", "nickname" : "outlet ark", "note" : "outlet ark"}, {" name ":" 1 _g01_zb ", "id":"538bf3c0-8554-11eb-bccd-c11a74ecd150", "nickname":null, "note":null }, { "name":"1_G04", "Id" : "53903980-8554-11 eb - BCCD - c11a74ecd150", "nickname" : "outlet ark", "note" : "outlet ark"}, {" name ":" 1 _g06 ", "Id" : "53928370-8554-11 eb - BCCD - c11a74ecd150", "nickname" : "outlet ark", "note" : "outlet ark"}, {" name ":" 1 _g03_zb ", "id":"946e6cf0-878f-11eb-b0f9-870b9c7d858c", "nickname":null, "note":null }, { "name":"1_G04_ZB", "id":"a9b92b90-878f-11eb-b0f9-870b9c7d858c", "nickname":null, "note":null }, { "name":"1_G05_ZB", "id":"b48ffb20-878f-11eb-b0f9-870b9c7d858c", "nickname":null, "note":null }, { "name":"1_G06_ZB", "id":"baf58de0-878f-11eb-b0f9-870b9c7d858c", "nickname":null, "note":null } ] }Copy the code
Conclusion:
This article describes how to aggregate TB interfaces on the Kettle platform to meet actual service requirements. If complex service scenarios are encountered, interface aggregation is inevitable. Using the Kettle platform as the middle platform is a good choice because the Kettle platform can meet almost all service aggregation and transformation requirements.