Websockets
LavinMQ supports both AMQP and MQTT over WebSocket connections, enabling browser-based clients and traversal of firewalls that block non-HTTP traffic.
Endpoints
| Path | Protocol |
|---|---|
/mqtt |
MQTT over WebSocket |
/ws/mqtt |
MQTT over WebSocket |
| any other path | AMQP over WebSocket |
WebSocket upgrade requests are accepted on the management HTTP port. Protocol selection follows this order:
- If the
Sec-WebSocket-Protocolheader is set, the protocol is selected from it:amqp(or any token starting withamqp, case-insensitive) — AMQP 0-9-1mqtt(or any token starting withmqtt, case-insensitive) — MQTT
- Otherwise, the path is used:
/mqttand/ws/mqttroute to MQTT; any other path routes to AMQP.
Conventionally, clients use /ws for AMQP, but the path itself is not significant when the sub-protocol header is set.
Port
WebSocket connections use the same HTTP port as the management UI and API:
| Config Key | Default |
|---|---|
port in [mgmt] |
15672 |
tls_port in [mgmt] |
15671 (WSS) |
How It Works
WebSocket connections are proxied to the internal AMQP or MQTT server. The WebSocket handler:
- Upgrades the HTTP connection to a WebSocket
- Detects the protocol from the sub-protocol header or URL path
- Creates a bidirectional IO bridge between the WebSocket and the protocol handler
From the protocol handler’s perspective, the connection behaves identically to a direct TCP connection.
Client IP
The client’s remote IP address is taken from the HTTP request’s TCP connection.
Ready to take the next steps?
Managed LavinMQ instance via CloudAMQP
LavinMQ has been built with performance and ease of use in mind - we've benchmarked a throughput of about 1,000,000 messages/sec . You can try LavinMQ without any installation hassle by creating a free instance on CloudAMQP. Signing up is a breeze.
Get started with CloudAMQP ->Help and feedback
We welcome your feedback and are eager to address any questions you may have about this piece or using LavinMQ. Join our Slack channel to connect with us directly. You can also find LavinMQ on GitHub.