Product Documentation

MQTT V3 Plug-in Reference

Previous Topic

Next Topic

Configuring a Persistence Topic

To tell c-tree to persist data automatically, a device, an MQTT client, the c-tree UI, or another source sends the FairCom MQTT Broker a specific configuration message with the topic of "ctreeAdministration" and a message body containing properties in JSON format. c-tree reads that JSON document to create a Persistence Topic, which defines how to create a table to store the data and how to map the table to the messages that will provide the data that is to be stored.

Below is an example of a JSON document in the body of a message that has the topic of "ctreeAdministration". This message causes c-tree to create a table named "table1" with one field (column) named "field1" with a data type of "CHAR", which is a string that can hold a maximum of 12 characters. It also registers the topic "myTopic" along with a message handler to process all incoming messages with that topic. The message handler extracts the value of the "property1" property and stores it in the "field1" column of a new row that it inserts into the table "table1".

{

"operation": "CreatePersistenceTopic",

"persistenceTopic": "myTopic",

"tableName": "table1",

"mapOfPropertiesToFields": [

{

"propertyPath": "property1",

"fieldName": "field1",

"fieldType": "CHAR",

"fieldWidth": 12

}

]

}

Below is an example of a JSON document in the body of a message that is published to the topic of "myTopic". c-tree uses the message handler created in the previous example, extracts the value of the "property1" property and stores it in the "field1" column of a new row that it inserts into the table "table1". In other words, when c-tree receives a "myTopic" message from an MQTT client, it inserts a new row into "table1" and stores "Hello World" in "field1".

{

"property1": "Hello World"

}

See Also:

 

In This Section

Example of a Configuration Message

Example of a Data Message

TOCIndex