Gatling’s MQTT support allows you to load test IoT message brokers and pub/sub systems using the MQTT protocol versions 3.1, 3.1.1, and 5. You can model realistic device behavior—connecting clients, subscribing to topics, publishing telemetry payloads, and verifying responses—all at high concurrency. This is particularly useful for validating IoT platforms, smart-home backends, and telemetry pipelines under realistic load.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gatling/gatling.io-doc/llms.txt
Use this file to discover all available pages before exploring further.
MQTT 3.1, 3.1.1, and 5 are supported. Some features introduced in MQTT 5 may not yet be available.
Project Setup
The Gatling MQTT plugin is not included by default. Add it alongside your standard Gatling dependencies.Add the MQTT dependency
- Java / Kotlin (Maven)
- Java / Kotlin (Gradle)
- JavaScript / TypeScript
- Scala (sbt)
MQTT Protocol Configuration
Use themqtt object to build a protocol configuration that is attached to your scenario via protocols(...).
Java
Scala
Key Protocol Options
| Option | Description |
|---|---|
broker(host, port) | MQTT broker address and port |
useTls(bool) | Enable/disable TLS encryption |
clientId(expression) | Client identifier; supports EL expressions |
cleanSession(bool) | Start with a clean session (no persistent subscriptions) |
credentials(user, pass) | Broker authentication |
keepAlive(seconds) | MQTT keep-alive interval |
qosAtMostOnce() | QoS level 0 — fire and forget |
qosAtLeastOnce() | QoS level 1 — at least once delivery |
qosExactlyOnce() | QoS level 2 — exactly once delivery |
retain(bool) | Retain the last published message on the broker |
reconnectAttemptsMax(n) | Maximum reconnection attempts |
unmatchedInboundMessageBufferSize(n) | Buffer size for unmatched inbound messages |
MQTT Actions
All MQTT actions are created withmqtt("actionName").
Connect
Virtual users must connect to the broker before performing any other action. Theconnect step establishes the MQTT session.
Java
Scala
Subscribe
Subscribe to one or more topics. You can set checks directly on the subscribe action to validate the first received message.Java
Scala
Publish
Publish a message to a topic. The body API supports the same types as HTTP request bodies.MQTT Checks
MQTT checks validate messages received after subscribing or publishing. Checks can be blocking (await) or non-blocking (expect).
Blocking Check (await)
The virtual user pauses until a matching message is received or the timeout expires. The first argument is a Duration; the optional second argument narrows the check to a specific reply topic:
Java
Non-Blocking Check (expect)
The virtual user continues execution immediately; the check is verified later:
Java
Wait for All Pending Checks
Usemqtt.waitForMessages() (called on the mqtt DSL object, not on a named action) to block until all pending non-blocking checks have resolved:
Java
Scala
Processing Unmatched Messages
Messages that arrive but do not match any active check can be buffered and processed later. Enable buffering by settingunmatchedInboundMessageBufferSize on the protocol.
The buffer is reset when:
- an outbound message is sent
processUnmatchedMessagesis called
mqtt.processUnmatchedMessages on the mqtt DSL object, passing the topic expression and a function:
Java
Scala
Full Example
Configuration Notes
MQTT support honors thessl and netty settings from gatling.conf. For TLS connections, set useTls(true) on the protocol and configure the relevant SSL settings in gatling.conf.