getMessagesFromMqApiSession

Retrieve undelivered messages from an MQ API client-subscribed topic

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": true to include the message's MQTT properties. It defaults to false.

Optionally, set "includeTransformFields": true to include the custom fields used for the transformation process's inputs and outputs. It defaults to false.

 

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 "includeMessageMetadata" property includes the message's "id", "timestamp", "error", and "log" properties when set to true.

Optional with default of false Boolean

true

false

includeMqttProperties

The "includeMqttProperties" property includes the MQTT properties in the response when set to true. Otherwise, omit the property or set it to false or null. MQTT properties are helpful when you need to troubleshoot MQTT messages.

Optional with default of false Boolean

true

false

includeTransformFields

The "includeTransformFields" property includes custom transform fields (if any) that a customer added to the integration table to when set to true. Otherwise, omit the property or set it to false or null. Custom transform fields are helpful when you want to see the outputs and inputs of transformations assigned to the integration table.

Optional with default of false Boolean

true

false

maxMessages

The "maxMessages" property specifies the number of messages to return from a "getMessages…" action. The number of returned messages will be equal to or less than this maximum.

Optional with default of 20 integer 1 to 100000

topic

The "topic" property specifies the unique, user-defined name for the topic.

  • The "topic" name is typically less than 150 characters.
  • The "topic" name will be used in all subsequent references to the topic, such as when re-configuring or deleting the topic.

 

Optional with default of "" string 1 to 65,500 bytes

topicFilter

The "topicFilter" property contains a topic filter, which may contain MQTT wildcard characters, #, and +. Without wildcard characters, it matches one topic. When containing wildcard characters, it may match one or more topics.

Optional with default of "" UTF-8 string topic names

 

Response properties ("result")

Property Description Type Limits (inclusive)

messages

The "messages" property specifies the message to be published to MQ as well as information about the message.

array of objects

1 or more objects including some or all of the following properties:

"binaryFormat"

"contentType"

"correlationData"

"expirySeconds"

"payload"

"responseTopic"

"retain"

"userProperties"