MQTT packet syntax

You can run MQTT packets through the MQTT wire listener.

MQTT clients send CONNECT and PUBLISH MQTT packets to the wire listener to connect and publish (insert) data into HCL OneDB™.The SUBSCRIBE packet and its associated packets are not supported by the wire listener.

For full syntax of MQTT packets, see http://mqtt.org.

CONNECT

You must include a CONNECT packet to identify the client user.

If authentication is enabled in the MQTT wire listener with the authentication.enable=true setting, you must specify a user name and password. The user name must include the database name with the following format: database_name.user_name. The following example connects to the database mydb as user joe with the password pass4joe:
CONNECT(mydb.joe, pass4joe)

The password is not encrypted by default. You can encrypt connections by configuring Secure Sockets Layer or Transport Layer Security encryption in the wire listener configuration file.

PUBLISH

The PUBLISH packet maps to the MongoDB insert or create command. The syntax of the PUBLISH packet without optional arguments is: PUBLISH(topicName, message). The topicName specifies the database and table name and the message contains the content to publish.

When you run the PUBLISH packet through the MQTT wire listener, the mandatory arguments have the following requirements:

  • The topicName field must identify the target database and table in the following format: database_name.table_name.
  • The message field must be in JSON format. If you are inserting data into a relational table, the field names in the JSON documents must correspond to column names in the target table. If you are inserting into a time series table specifying the timestamp field as a string in the JSON, you must specify the timestamp in ISO 8601 format. For example, { "id": "sensor1234", "tstamp": "2017-09-01T09:05:00", "reading": 87.5}

The following example inserts a JSON document into the sensordata table in the mydb database:

PUBLISH(mydb/sensordata, { "id": "sensor1234", "reading": 87.5})