The "configureTopic" action configures an existing MQTT topic or creates a new one. Configuring a topic is similar to altering a topic except the FairCom server automatically creates a topic when you specify a non-existent topic name.
Note If a topic already exists, you must use
"alterIntegrationTable"to change the retention settings:"retentionPolicy","retentionPeriod", and"retentionUnit".
- You may send a
"configureTopic"message repeatedly to update as few or many properties as desired. When you omit a property, its current value remains unchanged. Each time you send this message is sent, it modifies the topic’s settings. - If the topic has already been published to FairCom's servers,
"configureTopic"configures it. - If the topic has not yet been published to FairCom's servers,
"configureTopic"creates and configures it. - Creating a topic includes creating an integration table to store the topic’s messages. By default, tables are created in the ctreeSQL database, however, you can reconfigure this to any database you like by changing the configuration or the API session defaults.
- Each time this message is sent, it modifies the topic’s settings.
- The MQTT Publication service and the MQTT Subscription service are also preconfigured.
Request examples
Minimal
{
"apiVersion": "1.0",
"action": "configureTopic",
"params": {
"topic": "test/topic1"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Maximal
Note This example (which shows all of the available parameters) requires additional support in order to work. MQTT messages that clients publish to this topic ("acmefactory/line1/station1/acidbath/telemetry") will be automatically stored in the table's "source_payload" field when they arrive.
The broker will then publish an MQTT message to all subscribers of that topic. The contents of that message will come from the table field specified by the "outputPayloadField" parameter. If that parameter had specified the "source_payload" field, subscribing clients would receive the same message that arrived and was stored in the table. However, in this example, the "outputPayloadField" parameter is specifying the "aValidFieldName" field of the table. That means this topic requires a transform that reads the MQTT message payload from the "source_payload" field, performs some type of transformation on that data, and then stores the results in the "aValidFieldName" field (which will then be copied into the payload of the MQTT messages which the broker sends to all of this topic's subscribers).
{
"api": "mq",
"apiVersion": "1.0",
"requestId": "2",
"action": "configureTopic",
"params": {
"topic": "acmefactory/line1/station1/acidbath/telemetry",
"ownerName": "admin",
"databaseName": "faircom",
"tableName": "acmefactory_line1_station1_acidbath_telemetry",
"rebuildTable": "false",
"threads": 1,
"mqttPayloadType": "binary",
"retentionPolicy": "autoPurge",
"retentionPeriod": 30,
"retentionUnit": "day",
"maxInflightMessages": 20,
"maxDeliveryRatePerSecond": 0,
"retrySeconds": 5,
"downgradeQoS": false,
"newSubscriberDeliveryMode": "newMessages",
"newSubscriberMaxDeliveredMessages": 3,
"outputPayloadField": "aValidFieldName",
"operationIntent": "upsert",
"metadata": {},
"forwardToTopics": [],
"subscribeToExternalBroker": "false",
"forwardToExternalBrokers": [],
"label": {
"group": "group name",
"name": "label name"
}
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
Minimal
{
"result": {},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Maximal
{
"result": {},
"requestId": "2",
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Properties
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
databaseName |
The You specify this property when you want to use a different database instead of the default. This property is useful because objects, such as tables and code packages, can have the same name in multiple databases. This feature allows you to create multiple environments in the same server and reuse the same JSON actions in each environment. For example, you can create It is an error to set If no default database is specified during |
Defaults to the session's "defaultDatabaseName" property |
string | 1 to 64 bytes |
downgradeQoS |
The
|
Optional with default of false
|
Boolean |
|
forwardToExternalBrokers |
The "forwardToExternalBrokers" property specifies one or more brokers to forward the message to. All messages sent to this topic will be forwarded to each of these external brokers using the specified topic name. For more details, see “forwardToExternalBrokers”. |
Optional with default of |
array of objects |
Zero or more objects including some or all of the following properties:
|
forwardToTopics |
The
|
Optional with default of |
array of strings | One or more strings |
label |
The A label is a tag that you can add to some objects, such as an MQTT topic or session. You can use list actions such as The |
Optional with default of null
|
object | "label": {
"group": "group name",
"name": "label name"
} |
|
label .group |
The The The group name may contain up to 64 bytes of UTF-8 encoded characters. When you assign a group name to a label, the server automatically checks if the group name exists in the list of groups that the
|
Optional with default of ""
|
string | 1 to 64 bytes |
|
label .name |
The The The
|
Required - No default value | string | 1 to 64 bytes |
maxDeliveryRatePerSecond |
The
|
Optional with default of 0
|
int32 |
|
maxInflightMessages |
The
|
Optional with default of 0
|
int32 |
|
metadata |
The "metadata" property contains user-defined properties that add keywords and tags about the code package. The server indexes this field with a full-text index so you can search for any word or phrase to find code packages. |
Optional with default of {}
|
object | 0 or more key/value pairs |
mqttPayloadType |
The |
Optional with default of "binary"
|
string enum |
|
newSubscriberDeliveryMode |
The
|
Optional with default of |
string |
|
newSubscriberMaxDeliveredMessages |
The
|
Optional with default of -1
|
integer or "all" |
-1 to 2147483647 or "all"
|
operationIntent |
The
The "operationIntent" property values and their descriptions are as follows:
|
Optional with default of "upsert"
|
string |
|
outputPayloadField |
The
This makes it possible for the output from any transform to be used as the payload delivered to subscribers. |
Optional with default of |
string |
A user-defined field |
ownerName |
The You specify this property when you want to use a different account instead of the default. Your session's account must have the appropriate privileges to access the code package. This property is useful because objects, such as tables and code packages, can have the same name in the same database as long as different accounts own each object. This feature allows you to create duplicate objects for different users on the same server and reuse the same JSON actions on those objects. For example, an administrator can copy objects from a production environment to her account so she can troubleshoot an issue using the same JSON actions, JavaScript, and SQL code. It is an error to set If no default owner is specified during |
Optional with default of the session's "defaultOwnerName" property |
string | 1 to 64 bytes |
rebuildTable |
The
|
Optional with default of false
|
Boolean |
|
retentionPeriod |
The |
Optional with default of |
integer |
1 to 100
|
retentionPolicy |
The If not specified, the default found in the
retentionPolicy values:
|
Optional with default of |
string |
|
retentionUnit |
The If not specified, the default found in the
|
Optional with default of |
string |
|
retrySeconds |
The
|
Optional with default of |
integer |
|
subscribeToExternalBroker |
The
|
Optional with default of ""
|
string | Any previously defined name of a broker connection (see |
tableName |
The See table name in System specifications for the table naming requirements and limitations.
"params": {
"tableName": "ctreeTable"
} |
Required - No default value | string | 1 to 64 bytes |
threads |
The
|
Optional with default of 1
|
integer |
|
topic |
The
|
Optional with default of ""
|
string | 1 to 65,500 bytes |