How to use Java Client API to connect and send Data to the Digital Broker?

Introduction

We have developed 3 Java Clients to communicate with the platform: MQTTClient, that uses MQTT protocol; RestClient, that uses REST architecture; and BinaryRepositoryClient, that uses the RestClient and it is meant to be used for binary files exchange.

This is a lightweight library that does not require any Spring dependencies and is useful for light Applications in edge devices.



Adding Maven dependency

To use this API, you have to add the following repository to the project's pom.xml, like this:

<repositories> <repository> <id>onesait platform releases</id> <url>https://nexus.onesaitplatform.com/nexus/repository/releases/</url> </repository> <repository> <id>central Maven</id> <url>http://central.maven.org/maven2/</url> </repository> ... </repositories>

And then add the following dependency:

<dependency> <groupId>com.minsait.onesait.platform</groupId> <artifactId>onesaitplatform-java-client</artifactId> <version>${onesaitplatform.client.version}</version> </dependency>

where you need to change ${onesaitplatform.client.version}. For example now last version is 3.3.5-RELEASE with your Java API client version (see versions here: https://nexus.onesaitplatform.com/nexus/repository/releases/com/minsait/onesait/platform/onesaitplatform-java-client/)

Device based clients

MQTTClient and RestClient fit in this category, as they require a Device definition and a Token in order to make the connection.

  • Device: this is the device definition in the platform, e.g. TicketingApp

  • Token: the token associated with this device definition, e.g. e7ef0742d09d4de5a3687f0cfdf7f626

  • Ontology: the ontology used must be associated with the device, e.g. Ticket

An example would be:

You will also need to specify the server's URL:



Rest Client

Instantiate the REST as follows:



Now you can perform several operations as in this test:







MQTT Client



For the MQTT Client you can use either TCP or SSL connection (MQTT/MQTTS).

If you want to use MQTTS, you can specify the MQTTSecureConfiguration with the keyStore (.jks) path and its password, or use the default jks.



Otherwise, you can use MQTT over TCP:





Now connect client to make operations:





 

MQTT subscriptions

Check this tutorial: Subscribing to the Digital Broker using the Java Client API.

Non-device based clients



BinaryRepositoryClient fits in this category.



Binary Repository Client



This client operates with the Rest Client, and allows you to CRUD binary files in the platform.

To instantiate the client, you must specify the user, password and url.



Now you can add, remove, get or update a binary file.





NOTE: We recommended you to use GridFS as storage type for binary files, but Directory storage can be used.



Example:

For Prosumers project, we have created an example for inserting data into a Timeseries Ontology: Example_App.zip