Overview
Protocol extensions let you:- Test message brokers (MQTT, Kafka)
- Load test databases (Redis, SQL)
- Validate IoT infrastructure
- Test event-driven architectures
- Simulate thousands of protocol clients
MQTT
Thek6/x/mqtt extension adds first-class support for the MQTT protocol, enabling you to test MQTT brokers and IoT infrastructure.
Key features
- Event-driven architecture with lifecycle events (
connect,message,end,reconnect,error) - Synchronous and asynchronous methods for all operations
- Quality of Service (QoS) levels: 0, 1, and 2
- Message retention and Last Will and Testament (LWT) support
- Multiple broker URL schemas:
mqtt://,mqtts://,ws://,wss:// - SSL/TLS support with standard k6 TLS configuration
- Automatic metrics collection
Basic example
Async programming
Use async/await with MQTT event handlers:QoS levels
MQTT metrics
The extension automatically generates metrics:mqtt_connects- Connection attemptsmqtt_connect_duration- Connection timemqtt_publishes- Number of publish operationsmqtt_subscribes- Number of subscribe operationsmqtt_messages_received- Received messagesmqtt_messages_sent- Sent messages
Use cases
IoT load testing
Simulate thousands of IoT devices publishing sensor data
Message throughput
Test MQTT broker performance and message delivery rates
QoS validation
Verify Quality of Service guarantees under load
Event-driven systems
Test MQTT-based microservices and event architectures
Redis
Thek6/x/redis extension provides a client library for interacting with Redis databases directly from k6 scripts.
Features
- Load test Redis databases
- Use Redis as a data store for test-script logic
- Promise-based async API
- Support for common Redis commands
Basic example
Connection options
Common operations
Use cases
Cache load testing
Test Redis cache performance under high load
Session storage
Validate session management at scale
Test data sharing
Share data between VUs using Redis
Rate limiting
Test rate limiting implementations
SQL
Thek6/x/sql extension enables testing of SQL databases including PostgreSQL, MySQL, SQLite, and more.
Supported databases
- PostgreSQL
- MySQL / MariaDB
- Microsoft SQL Server
- SQLite
- ClickHouse
Basic example
Connection strings
Transaction example
Use cases
Database load testing
Test database performance under concurrent queries
Connection pooling
Validate connection pool behavior
Transaction testing
Test transaction isolation and deadlocks
Query performance
Measure query execution times at scale
Using protocol extensions
All official protocol extensions support automatic resolution:Build custom binary
To bundle protocol extensions in a custom binary:Combining protocols
Test complex systems using multiple protocols:Best practices
Connection pooling
Reuse connections in the init context when possible
Async operations
Use async/await for non-blocking protocol operations
Error handling
Always handle connection errors and timeouts
Resource cleanup
Close connections in teardown or finally blocks
Next steps
Explore Extensions
Discover more k6 extensions
Build Custom Binary
Bundle extensions with xk6
xk6-disruptor
Add chaos testing capabilities
Browser Extension
Test frontend with browser automation