mqtt

Found an error? Have a suggestion?Edit this page on GitHub

MQTT Bindings

This document defines how to describe MQTT-specific information on AsyncAPI.

It applies to all versions of MQTT, although specific binding fields may only apply to particular versions.

Version

Current version is 0.2.0.

Server Binding Object

This object contains information about the server representation in MQTT.

Fixed Fields
Field NameTypeMQTT VersionsDescription
clientIdstring3, 5The client identifier.
cleanSessionboolean3, 5Whether to create a persistent connection or not. When false, the connection will be persistent. This is called clean start in MQTTv5.
lastWillobject3, 5Last Will and Testament configuration. topic, qos, message and retain are properties of this object as shown below.
lastWill.topicstring3, 5The topic where the Last Will and Testament message will be sent.
lastWill.qosinteger3, 5Defines how hard the broker/client will try to ensure that the Last Will and Testament message is received. Its value MUST be either 0, 1 or 2.
lastWill.messagestring3, 5Last Will message.
lastWill.retainboolean3, 5Whether the broker should retain the Last Will and Testament message or not.
keepAliveinteger3, 5Interval in seconds of the longest period of time the broker and the client can endure without sending a message.
sessionExpiryIntervalinteger | Schema Object | Reference Object5Interval in seconds or a Schema Object containing the definition of the interval. The broker maintains a session for a disconnected client until this interval expires.
maximumPacketSizeinteger | Schema Object | Reference Object5Number of bytes or a Schema Object representing the maximum packet size the client is willing to accept.
bindingVersionstringThe version of this binding. If omitted, "latest" MUST be assumed.

This object MUST contain only the properties defined above.

Examples
1servers:
2  production:
3    bindings:
4      mqtt:
5        clientId: guest
6        cleanSession: true
7        lastWill:
8          topic: /last-wills
9          qos: 2
10          message: Guest gone offline.
11          retain: false
12        keepAlive: 60
13        sessionExpiryInterval: 600
14        maximumPacketSize: 1200
15        bindingVersion: 0.2.0
1servers:
2  production:
3    bindings:
4      mqtt:
5        sessionExpiryInterval:
6          type: integer
7          minimum: 30
8          maximum: 1200
9        maximumPacketSize:
10          type: integer
11          minimum: 256
12        bindingVersion: 0.2.0

Channel Binding Object

This object MUST NOT contain any properties. Its name is reserved for future use.

Operation Binding Object

This object contains information about the operation representation in MQTT.

Fixed Fields
Field NameTypeApplies ToMQTT VersionsDescription
qosintegerPublish, Subscribe3, 5Defines the Quality of Service (QoS) levels for the message flow between client and server. Its value MUST be either 0 (At most once delivery), 1 (At least once delivery), or 2 (Exactly once delivery).
retainbooleanPublish3, 5Whether the broker should retain the message or not.
messageExpiryIntervalinteger | Schema Object | Reference ObjectPublish5Interval in seconds or a Schema Object containing the definition of the lifetime of the message.
bindingVersionstringThe version of this binding. If omitted, "latest" MUST be assumed.

This object MUST contain only the properties defined above.

Examples
1channels:
2  user/signup:
3    publish:
4      bindings:
5        mqtt:
6          qos: 2
7          retain: true
8          messageExpiryInterval: 60
9          bindingVersion: 0.2.0
1channels:
2  user/signup:
3    publish:
4      bindings:
5        mqtt:
6          messageExpiryInterval:
7            type: integer
8            minimum: 30
9            maximum: 300
10          bindingVersion: 0.2.0
1channels:
2  user/signup:
3    subscribe:
4      bindings:
5        mqtt:
6          qos: 2
7          bindingVersion: 0.2.0

Message Binding Object

This object contains information about the message representation in MQTT.

Fixed Fields
Field NameTypeMQTT VersionsDescription
payloadFormatIndicatorinteger5Either: 0 (zero): Indicates that the payload is unspecified bytes, or 1: Indicates that the payload is UTF-8 encoded character data.
correlationDataSchema Object | Reference Object5Correlation Data is used by the sender of the request message to identify which request the response message is for when it is received.
contentTypestring5String describing the content type of the message payload. This should not conflict with the contentType field of the associated AsyncAPI Message object.
responseTopicURI string | Schema Object | Reference Object5The topic (channel URI) for a response message.
bindingVersionstringThe version of this binding. If omitted, "latest" MUST be assumed.

This object MUST contain only the properties defined above.

Examples
1channels:
2  user/signup:
3    subscribe:
4      message:
5        bindings:
6          mqtt:
7            contentType: "application/json"
8            correlationData:
9              type: string
10              format: uuid
11            bindingVersion: 0.2.0
1channels:
2  userSignup:
3    address: user/signup
4    messages:
5      userSignup:
6        bindings:
7          mqtt:
8            payloadFormatIndicator: 1
9            contentType: "application/json"
10            correlationData:
11              type: string
12              format: uuid
13            responseTopic:
14              type: string
15              pattern: "response/client/([a-z1-9]+)"
16            bindingVersion: 0.2.0
Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub