The "getMessagesFromMqApiSession" action retrieves undelivered messages from topics to which an MQ API client has subscribed. This action only applies to sessions created using the "createMqApiSession", and this is why the phrase "MqApi" is in the name of the action.
The MQ client is identified by the required "clientName" property. An MQ API session with that client identifier must already exist; otherwise, it returns an error. It also returns an error when the "clientName" is used by an MQTT connection.
Each time you call this action with the same "clientName", the server starts where it left off and delivers the next set of messages published to that client. It retrieves undelivered messages up to the number specified by "maxMessages". The message payload is encoded according to the "binaryFormat" property.
If you subscribe to multiple topics, the server returns messages from all of them. You can use the "topic" property to retrieve messages from only one of your subscribed topics.
The typical pattern for using this action is to first call the "createMqApiSession" action to create a new session. Then, use the "subscribeToMq" action to subscribe to topics. You can then repeatedly call the "getMessagesFromMqApiSession" action to retrieve messages as clients publish them.
An application can retrieve messages sent to a shared topic, which is a topic starting with $share/. A shared topic works differently from a normal topic because the server distributes each message to a different subscriber rather than sending each message to each subscriber. Each time a subscriber uses the "getMessagesFromMqApiSession" action to retrieve a message, the server removes the message from the queue and prevents that message from being sent to another subscriber. If the application encounters an error processing a message, it must publish the message back to the topic so it can be processed by another subscriber.
Tip An application can use
"getMessagesFromMqApiTopic"to retrieve shared messages without removing them from the queue.
Warning
Clients must use unique client names so they do not consume each other's messages. If multiple processes use the same value for the
"clientName"property in the"getMessagesFromMqApiSession"action, each process denies other processes from retrieving messages that it has retrieved. You may want to do this to implement distributed command processing. On the other hand, if you want to use the event streaming technique to retrieve messages, do not subscribe to topics; Instead, use the"getMessagesFromMqTopic"action to retrieve messages.Optionally, set
"includeMqttProperties": trueto include the message's MQTT properties. It defaults tofalse.Optionally, set
"includeTransformFields": trueto include the custom fields used for the transformation process's inputs and outputs. It defaults tofalse.
Request examples
Maximal
{
"api": "mq",
"action": "getMessagesFromMqApiSession",
"params": {
"topic": "test/topic1",
"clientName": "client1",
"maxMessages": 100,
"binaryFormat": "hex",
"includeMessageMetadata": true,
"includeMqttProperties": true,
"includeTransformFields": true
},
"responseOptions": {
"dataFormat": "arrays",
"numberFormat": "number",
"binaryFormat": "base64",
"variantFormat": "json"
},
"apiVersion": "1.0",
"debug": "max",
"requestId": "optionalUniqueRequestIdFromTheClient",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Retrieve the next batch of 100 messages
{
"api": "mq",
"action": "getMessagesFromMqApiSession",
"params":
{
"clientName": "required unique MQ API client identifier",
"maxMessages": 100
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Retrieve all undelivered messages
{
"api": "mq",
"action": "getMessagesFromMqApiSession",
"params":
{
"clientName": "required unique MQ API client identifier"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Retrieve up to 100 unsent messages from the subscription, format the message payload as JSON, and include all expired messages, MQTT metadata, MQTT properties, and transform fields
{
"api": "mq",
"action": "getMessagesFromMqApiSession",
"params":
{
"clientName": "required unique MQ API client identifier",
"topicFilter": "topic#",
"maxMessages": 100,
"binaryFormat": "json",
"includeMessageMetadata": true,
"includeMqttProperties": true,
"includeTransformFields": true
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response example
Successful
{
"authToken": "gOS2OeL4HgtpLUSVqPwAvtDwWEqSfZIkcEKOie6DP0zgiOWZd8IOBLbQgv2fiRHm",
"result": {
"messages": []
},
"requestId": "00000004",
}
Properties
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
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". |
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 |
includeMessageMetadata |
The |
Optional with default of false
|
Boolean |
|
includeMqttProperties |
The |
Optional with default of false
|
Boolean |
|
includeTransformFields |
The |
Optional with default of false
|
Boolean |
|
maxMessages |
The |
Optional with default of 20
|
integer |
1 to 100000
|
topic |
The
|
Optional with default of ""
|
string | 1 to 65,500 bytes |
topicFilter |
The |
Optional with default of ""
|
UTF-8 string | topic names |
Response properties ("result")
| Property | Description | Type | Limits (inclusive) |
|---|---|---|---|
messages |
The |
array of objects |
1 or more objects including some or all of the following properties:
|