class
MQTT::Client
- MQTT::Client
- Reference
- Object
Overview
Connects with MQTT 5.0 and falls back to 3.1.1 when the broker will not take it, exposing what the two protocols have in common.
A broker that rejects the version closes the connection, so negotiation needs a fresh transport for the retry. That is why this takes a factory rather than a transport:
client = MQTT::Client.new { MQTT::Transport::TCP.new("test.mosquitto.org") }
client.connect
client.version # => MQTT::Version::V5
Version specific features stay on MQTT::V5::Client, reachable through
#v5 once you know what you are talking to.
Defined in:
mqtt/client.crConstructors
Instance Method Summary
- #closed? : Bool
-
#connect(username : String | Nil = nil, password : String | Nil = nil, keep_alive : Int32 = 60, client_id : String = MQTT.generate_client_id, clean_start : Bool = true, will_flag : Bool = false, will_qos : Int32 | QoS = 0, will_retain : Bool = false, will_topic : String | Nil = nil, will_payload : String | Bytes | Nil = nil, timeout : Time::Span | Nil = @timeout, keep_alive_active : Bool = true) : Version
Tries 5.0, then 3.1.1.
- #disconnect(send_msg = true) : Nil
- #last_ping_response : Time | Nil
-
#negotiated : V3::Client | V5::Client
The negotiated client.
- #ping(timeout : Time::Span | Nil = @timeout) : Nil
- #publish(topic : String, payload = "", retain : Bool = false, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout)
-
#session_present? : Bool
Whether the broker resumed an existing session
- #subscribe(*topics, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout, &callback : String, Bytes, Bool -> Nil)
- #subscriptions : Hash(String, QoS)
- #terminated? : Bool
- #unsubscribe(*topics, timeout : Time::Span | Nil = @timeout)
-
#v3 : V3::Client | Nil
The 3.1.1 client, when that is what was negotiated
-
#v5 : V5::Client | Nil
The 5.0 client, when 5.0 is what was negotiated
-
#version : Version | Nil
The version actually negotiated, nil until
#connecthas run - #wait_close : Nil
Constructor Detail
Instance Method Detail
Tries 5.0, then 3.1.1. Once a version is settled the underlying client keeps the factory, so reconnections use it directly and never re-probe
The negotiated client. Raises until #connect has succeeded
The version actually negotiated, nil until #connect has run