Skip to content

feat(rumqttd): configurable protocol version for WebSocket listeners#1039

Open
conglp90 wants to merge 1 commit into
bytebeamio:mainfrom
conglp90:feat/ws-v5-protocol
Open

feat(rumqttd): configurable protocol version for WebSocket listeners#1039
conglp90 wants to merge 1 commit into
bytebeamio:mainfrom
conglp90:feat/ws-v5-protocol

Conversation

@conglp90
Copy link
Copy Markdown

@conglp90 conglp90 commented Apr 2, 2026

Summary

WebSocket listeners are currently hardcoded to MQTT v4 (broker.rs:251), with a TODO comment:

//TODO: Add support for V5 procotol with websockets. Registered in config or on ServerSettings

This PR resolves that TODO by adding a protocol field to ServerSettings.

Changes (~27 LOC, 2 files)

src/lib.rs

  • Add ProtocolVersion enum (V4, V5) with serde support and Default = V4
  • Add #[serde(default)] pub protocol: ProtocolVersion to ServerSettings

src/server/broker.rs

  • Import ProtocolVersion
  • Match on config.protocol when spawning WS servers → Server<V4> or Server<V5>

Config example

# Default (backward compatible) — MQTT v4 over WebSocket
[ws.1]
name = "ws-v4"
listen = "0.0.0.0:8883"
next_connection_delay_ms = 1

# New — MQTT v5 over WebSocket
[ws.2]
name = "ws-v5"
listen = "0.0.0.0:8884"
next_connection_delay_ms = 1
protocol = "v5"

Backward compatibility

  • protocol defaults to v4 via #[serde(default)], so existing configs work unchanged
  • No changes to v4/v5 TCP listeners, network layer, or handshake logic

Testing

Tested with:

  • Python paho-mqtt (MQTTv5 over WebSocket) — connect, publish, subscribe, request-response with response_topic + correlation_data
  • mqtt.js browser client (protocolVersion: 5 over WS)
  • All v5 features (response_topic, correlation_data) work correctly over WebSocket

Add ProtocolVersion enum (v4/v5) to ServerSettings, allowing WebSocket
listeners to be configured with either MQTT v4 or v5 protocol.

Previously, WebSocket listeners were hardcoded to V4. This patch reads
a 'protocol' field from config (default: v4 for backward compat) and
spawns the appropriate Server<V4> or Server<V5>.

Changes:
- src/lib.rs: Add ProtocolVersion enum + protocol field to ServerSettings
- src/server/broker.rs: Match on protocol when spawning WS servers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant