This action publishes one or more messages to a topic. MQ API and MQTT clients can subscribe to a topic and receive these messages. The required "clientName" property identifies the MQ API session used to publish the messages. The FairCom server tracks session statistics so you can monitor the health of a client and its session, including the timestamp of the last published message, the publish rate, the topics the session publishes to, etc.
When you set the "binaryFormat" property to "utf8" or "JSON", the server automatically assigns the MQTT 5 Payload Format Indicator property to 1 to indicate that the message payload contains UTF-8-encoded characters, such as JSON.
Request examples
Minimal
{
"action": "publishMessagesToMq",
"params": {
"clientName": "client1",
"topic": "test/topic1",
"messages": [
{
"payload": "A143C2F"
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Typical
{
"api": "mq",
"action": "publishMessagesToMq",
"params": {
"clientName": "client1",
"topic": "test/topic1",
"messages": [
{
"payload": "This is the first message payload for the typical example.",
"mqttPayloadType": "utf8"
},
{
"payload": "This is the second message payload for the typical example.",
"mqttPayloadType": "utf8"
},
{
"payload": "This is the third message payload for the typical example.",
"mqttPayloadType": "utf8"
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Maximal
{
"apiVersion": "1.0",
"api": "mq",
"action": "publishMessagesToMq",
"params": {
"clientName": "client1",
"topic": "test/topic1",
"messages": [
{
"payload": "DEADBEEF",
"binaryFormat": "hex",
"contentType": "IanaMediaType or a CustomType",
"correlationData": "any JSON value up to 65500 bytes",
"expirySeconds": 60,
"retain": true,
"responseTopic": "topic/name/for/subscriber/to/respond/to",
"userProperties": [
{
"key": "some key",
"value": "some value"
}
]
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession",
"requestId": "3",
"debug": "max"
}Publish one message to topic1
{
"api": "mq",
"action": "publishMessagesToMq",
"params":
{
"clientName": "client1",
"topic": "test/topic1",
"messages": [
{
"payload": "This is the message payload.",
"mqttPayloadType": "utf8"
}
]
},
"apiVersion": "1.0",
"debug": "max",
"requestId": "optionalUniqueRequestIdFromTheClient",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Publish one message to table mqtt_msg_test_topic1
{
"api": "mq",
"action": "publishMessagesToMq",
"params":
{
"clientName": "a unique client identifier",
"topic": "test/topic1",
"databaseName": "faircom",
"ownerName": "admin",
"tableName": "mqtt_msg_test_topic1",
"messages": [
{
"payload": "This is the message payload.",
"mqttPayloadType": "utf8"
}
]
},
"apiVersion": "1.0",
"debug": "max",
"requestId": "optionalUniqueRequestIdFromTheClient",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response example
Success
{
"result": {},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Properties
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
clientName |
The "clientName" property specifies the unique name that identifies the client to the FairCom MQ engine. |
Optional with default of ""
|
string | 0 to 65,550 bytes |
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 |
messages |
The |
Optional with default of []
|
array of objects |
1 or more objects including some or all of the following properties:
|
|
messages .binaryFormat |
The "binaryFormat" property designates the format of binary values embedded in JSON strings. For more details, see "binaryFormat". |
Optional with default of "hex"
|
string | One of the following: "base64", "hex", or "byteArray". |
|
messages .contentType |
The |
Optional with default of ""
|
string | an IANA media or custom type |
|
messages .correlationData |
The |
Optional with default of ""
|
JSON | 0 to 65,500 bytes |
|
messages .expirySeconds |
The |
Optional with default of null
|
integer | No limits |
|
messages .mqttPayloadType |
The |
Optional with default of "json"
|
string enum |
|
|
messages .payload |
The |
Required - No default value | string | The message's payload |
|
messages .responseTopic |
The |
Optional with default of ""
|
string | topic name for the response |
|
messages .retain |
The |
Optional with default of false
|
Boolean |
|
|
messages .userProperties |
The "userProperties": [
{
"key": "some key",
"value": "some value"
}
] |
Optional with default of null
|
array | 0 or more key/value pairs |
|
messages userProperties .key |
The "key" property is part of an optional key-value object that is defined in an array in the "userProperties" property. It is a user-defined string value. |
Optional with default of
Required in the Key-Value API |
string | 1 to 128 bytes |
|
messages userProperties .value |
The
In Key-Value actions, the required |
Required - No default value | string |
|
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 |
tableName |
The See table name in System limits for the table naming requirements and limitations.
"params": {
"tableName": "ctreeTable"
} |
Required - No default value | string | 1 to 64 bytes |
topic |
The
|
Optional with default of ""
|
string | 1 to 65,500 bytes |