Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: /docs/k6/latest/javascript-api/k6-x-mqtt/client/connect.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/k6-x-mqtt/client/connect/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
Client.connect()
Establishes a connection to an MQTT broker. When the connection is successfully established, the connect event is triggered.
Signature
client.connect(url, options)Parameters
| Parameter | Type | Description |
|---|---|---|
| url | string | Broker URL (for example, mqtt://broker.emqx.io:1883) |
| options | object | Optional connection configuration |
| options.keepalive | number | Keep-alive interval in seconds (default: 60) |
| options.connect_timeout | number | Connection timeout in milliseconds (default: 30000) |
| options.clean_session | boolean | Whether to start with a clean session (default: true) |
| options.servers | string[] | Array of broker URLs for failover |
| options.tags | object | Custom tags for metrics (key-value pairs) |
Supported broker URL schemas
| Schema | Description |
|---|---|
mqtt:// | Plain TCP connection (no encryption) |
mqtts:// | Secure connection over SSL/TLS |
tcp:// | Alias for mqtt:// |
ssl:// | Alias for mqtts:// |
tls:// | Alias for mqtts:// |
ws:// | MQTT over WebSocket |
wss:// | MQTT over secure WebSocket |
If the schema is omitted, mqtt:// is used as the default.
SSL/TLS configuration
The extension uses standard k6 TLS configuration for all SSL/TLS settings. Configure certificates, verification, and other TLS-related options using k6’s environment variables and configuration files.
Was this page helpful?
Related resources from Grafana Labs

