Repository navigation
Added MQTT requests - #216
Conversation
Adds Protocol::MqttRequest with the MQTT version, client ID, clean session, keep-alive, max packet size, subscriptions, publish options and message log. The broker is the request URL, credentials come from basic auth. Sending and the TUI view are temporary placeholders for now.
Uses rumqttc-next (MQTT 3.1.1 and 5, mqtt:// and mqtts://) behind a small wrapper, the connection runs in its own task and receives publish and disconnect commands through a channel. - CONNACK is shown as the status, session present and MQTT 5 properties as headers - Enabled subscriptions are subscribed on connect, messages and events are logged - An empty client ID with clean session off is refused instead of panicking - Messages over the max packet size are refused instead of closing the connection - Explains the error when a broker answers a clean session with session present - CLI send prints messages as they arrive and publishes stdin lines
- Param tabs for MQTT requests: Auth, Connect, Subscribe, Publish and Scripts - Connect tab edits the version, client ID, clean session, keep alive and max packet size - Subscribe tab lists the topic filters, QoS is changed with enter - Publish tab sets the topic, QoS and retain, confirming the payload publishes it - Messages result tab shows the published, received and connection events - Headers result tab shows session present and the MQTT 5 CONNACK properties - MQTT can be chosen when creating a new request - The messages tab rendering is shared between websocket and MQTT requests
Replaces rumqttc-next with upstream rumqttc 0.25.1, as agreed in the issue. The client and its event loop are kept apart since the event loop is not Sync. - Option values rumqttc panics on are refused with a clear error first: an empty MQTT 3.1.1 client ID with clean session off, an MQTT 5 keep alive under 5 seconds - TLS uses its own rustls configuration with the aws_lc_rs provider instead of the default one, which panics when system certificates cannot be loaded - Accept invalid certs and accept invalid hostnames now apply to MQTT over TLS, with the same meaning as for HTTP - Added an MQTT 5 session expiry field (default 3600 seconds), sent when clean session is off and a client ID is set - The URL scheme error lists mqtt://, mqtts://, tcp:// and ssl:// - Removed the session present workaround, rumqttc accepts it
- request new takes --mqtt-version, --client-id, --no-clean-session, --session-expiry, --keep-alive, --max-packet-size, --add-subscription, --publish-topic, --publish-qos and --publish-retain - MQTT options are refused on other protocols, and headers on MQTT requests - request info shows the MQTT settings - New MQTT requests no longer get the HTTP default headers, from the CLI or the TUI
- More than 10 subscriptions, or a burst of publishes, could block forever since rumqttc's request queue is only emptied by the event loop. Polling and sending now run in separate tasks - A pre-request script changing the protocol is a script error instead of a panic - request send --cookies no longer panics when there are no cookies - Deleting a connected request, or its collection, disconnects it - A duplicated request does not share the original's connection - A max packet size of 0 is refused - Accepting invalid certs no longer needs platform certificates - The MQTT 5 packet size estimate includes the properties length
… output Julien-cpsn#215 - stdin is read from a plain thread, a pending tokio stdin read kept the process alive once the connection had ended - Messages are copied before printing, printing under the request lock blocked the connection from polling when stdout was slow
Covers URL and port handling, input checks, environment variables, the packet size limit, the certificate verifier with the request settings, saving and loading requests, the example collections and the request new flags. No new dependencies.
|
Hello @helenkwok , Looks fantastic @ me when the PR is ready for review. Sorry but it might take a long time as you have added 2900 lines of code lol Have a great day! |
…lien-cpsn#215 - The result view refresh after a response or a message assumed a selected request, so an MQTT message or disconnection after unselecting or deleting the request panicked. A slow HTTP response did the same - A pre-request script changing the protocol of an MQTT request now says so
…psn#215 An MQTT 5 broker can advertise a lower maximum packet size than the request's in its CONNACK. rumqttc then refuses to send a larger message by closing the whole connection, so such a message is now refused on its own, with the broker's limit in the event.
|
@Julien-cpsn it's ready for review, thank you! To make the 2,950 lines less painful:
|
|
Thank you so much for merging, and for the kind words in the release notes, Julien! One small thing I noticed while trying 0.24.0 with a theme file from 0.23: besides the new QUERY = "LightMagenta"It might be worth adding next to the MQTT snippet in the v0.24.0 release notes. |
|
@helenkwok yes you are totally right, I forgot lol Thank you |
Closes #215.
Adds MQTT requests to ATAC, using upstream
rumqttc0.25.1 as agreed in the issue. Works with MQTT 3.1.1 and 5, over TCP (mqtt://,tcp://) and TLS (mqtts://,ssl://).How it works
An MQTT request is a new protocol next to HTTP and WebSocket. The request URL is the broker, and the username and password come from basic auth. It reuses the WebSocket view: sending the request connects, messages arrive in the Messages tab, and it stays connected until you disconnect.
Param tabs:
Result tabs:
session presentand the MQTT 5 CONNACK propertiesThe CONNACK reason code is shown as the status. A refused connection shows the error instead, such as the broker's reason code.
CLI:
request new -p MQTTtakes--mqtt-version,--client-id,--no-clean-session,--session-expiry,--keep-alive,--max-packet-size,--add-subscription <TOPIC> <QOS>and--publish-topic/--publish-qos/--publish-retain.request sendprints messages as they arrive, and publishes each line read from stdin to the publish topic.request infoshows the MQTT settings.Stability
rumqttcpanics on a few inputs, so ATAC checks for them first and shows an error instead:aws_lc_rsprovider, which ATAC already uses.Other details:
rumqttcaccepts brokers that sendsession presenton a clean connect. That's a spec violation, but some real brokers do it.get_selected_request_as_local. A slow HTTP response could trigger it too.Dependencies and size
rumqttcandrustls-native-certs.rumqttc,flume,tokio-stream,rustls-pemfile,rustls-webpki0.102).Tested
session presenton clean connects, and a local mosquitto withmax_packet_size 1000: an oversized message is refused on its own and the connection stays up.session presenton a clean connect; garbage, malformed or oversized packets; invalid UTF-8 topics; unknown topic aliases; packet id 0; unsolicited acks; dropped connections; missing ping responses; a broker DISCONNECT with a reason; SUBACK failures; incoming QoS 2; retained, empty, binary and Unicode messages; 20,000 messages in a burst, including while nothing reads the CLI's output. None crash or hang, and the CLI exits when the connection ends.cargo test, no new dependencies) for URL and port handling, the input checks, environment variables, the packet size limits (the request's and the broker's), the certificate verifier with the request settings (with an embedded test certificate authority), saving and loading requests, loading every example collection, and therequest newflags.The GIF and an example collection are in
gifs/mqtt.gifandexample_resources/collections/mqtt.json.Not included
rumqttchas a feature for it, but it adds dependencies. It could come in a follow-up if wanted.mosquitto_pub/mosquitto_subexport would be possible if you'd like one.Noticed while testing, not changed here
These already exist upstream and aren't MQTT-specific, so I left them for you to decide:
{{USER}}in an environment file is replaced with the OS user.