Product Documentation

MQTT V3 Plug-in Reference

Previous Topic

Next Topic

Handling of "CreatePersistenceTopic"

When c-tree receives the "CreatePersistenceTopic" operation, it does the following:

  1. If the Persistence Topic already exists, the operation fails. c-tree logs an error to its CTSTATUS.FCS file.

    c-tree ignores the operation and continues to collect data using the previously set up Persistence Topic.

  2. c-tree creates a table to store data from future messages that will be published to the Persistence Topic.

    If the specified table does not exist in the target database, c-tree creates it.

    If the table exists, c-tree validates the fields in the table against the fields specified in the "CreatePersistenceTopic" operation.

    • If the operation specifies additional fields or different field data types, the operation fails and c-tree logs an error to its CTSTATUS.FCS file.

    You can set properties in the operation to define table characteristics, such as:

    • Defining table fields
    • Setting a data retention policy
    • Adding an Automatic Timestamp Field with optional index
    • Making the table ready for Asynchronous Data Replication or optimizing the table for high-speed inserts (see "tableReplicationReady" below)
  3. c-tree creates a message handler to process future messages published to the Persistence Topic.

    When the message handler receives an incoming MQTT message that matches the Persistence Topic, it does the following.

    • It creates a record in the table assigned to the Persistence Topic when at least one non-null value can be placed in one field.
    • It extracts the JSON document from the payload of the message.
    • It extracts the value of each property in the JSON document.
    • It uses "mapOfPropertiesToFields" to look up how a property is mapped to a field in the table.
    • If necessary it converts the property value to match the target field’s data type.
    • It stores the value into the field.
    • It inserts the record.

    The message handler sets a field value to NULL:

    • When a field does not have matching JSON properties; i.e. when a mapped JSON property is missing.
    • When an error occurs while converting a property value to the target field’s data type.
      • c-tree also logs an error to CTSTATUS.FCS that a data conversion failed.

    The message handler does not insert a record:

    • When a JSON document is invalid.
    • When a JSON document in the message’s payload has no properties.
    • When no JSON properties are mapped to fields in the target table.
    • When no JSON property values can be converted to the field types in the target table.

    In each case, c-tree logs an error to CTSTATUS.FCS that a data conversion failed.

Using CreatePersistenceTopic without a DeletePersistenceTopic

If a table is created via the MQTT "CreatePersistenceTopic", but never gets a "DeletePersistenceTopic" message, FairCom Edge will recreate those tables whenever it cannot find them. This usually happens on startup.

In that state, if you stop FairCom Edge, delete everything in the /data/ directory, and restart FairCom Edge, it will create those tables automatically. To get a "clean start" for FairCom Edge when it is in this state, you must delete all the files in the server/web/mqtt/active/ directory. The files in there are named <tableName>.json.

So to get out of that state, you need to delete the /data/ folder along with those JSON files from that directory.

TOCIndex