MQTT::Client
Inherits Reference / Object
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.
Constructors
new(timeout : Time::Span | Nil = MQTT::ClientBase::DEFAULT_TIMEOUT, max_packet_size : UInt32 = MQTT::DEFAULT_MAX_PACKET_SIZE, reconnect : MQTT::Reconnect = MQTT::Reconnect.new, &factory : -> Transport)
SourceInstance methods
closed?
Sourceconnect(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. Once a version is settled the underlying client keeps the factory, so reconnections use it directly and never re-probe
disconnect(send_msg = true) : Nil
Sourcelast_ping_response
Sourceping(timeout : Time::Span | Nil = @timeout) : Nil
Sourcepublish(topic : String, payload = "", retain : Bool = false, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout)
Sourcesubscribe(*topics, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout, &callback : String, Bytes, Bool -> Nil)
Sourcesubscriptions
Sourceterminated?
Sourceunsubscribe(*topics, timeout : Time::Span | Nil = @timeout)
Sourcewait_close
Source