class MQTT::V5::Client

Overview

An MQTT 5.0 client.

The transport lifecycle, request pipeline, keep alive and reconnection all live in MQTT::ClientBase. What follows is the 5.0 specific half.

The substantive difference from 3.1.1 is that acknowledgements now carry a reason: a PUBACK can say the publish was rejected, and a SUBACK can reject individual filters. Those are raised rather than resolved

Defined in:

mqtt/v5/client.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class MQTT::ClientBase

closed? closed?, last_ping_response : Time | Nil last_ping_response, max_packet_size : UInt32 max_packet_size, parse_message(io) parse_message, ping(timeout : Time::Span | Nil) : Nil ping, terminated? : Bool terminated?, timeout : Time::Span | Nil timeout, timeout=(timeout : Time::Span | Nil) timeout=, wait_close : Nil wait_close

Constructor methods inherited from class MQTT::ClientBase

new(timeout : Time::Span | Nil, max_packet_size : UInt32, factory : Proc(Transport), reconnect : MQTT::Reconnect)
new(transport : Transport, timeout : Time::Span | Nil = DEFAULT_TIMEOUT, max_packet_size : UInt32 = MQTT::DEFAULT_MAX_PACKET_SIZE)
new

Constructor Detail

def self.new(transport : Transport, timeout : Time::Span | Nil = DEFAULT_TIMEOUT, max_packet_size : UInt32 = MQTT::DEFAULT_MAX_PACKET_SIZE) #

[View source]
def self.new(timeout : Time::Span | Nil = DEFAULT_TIMEOUT, max_packet_size : UInt32 = MQTT::DEFAULT_MAX_PACKET_SIZE, reconnect : MQTT::Reconnect = MQTT::Reconnect.new, &factory : -> Transport) #

[View source]

Class Method Detail

def self.topic_matches(filter : String, topic : String) #

[View source]

Instance Method Detail

def assigned_client_id : String | Nil #

The identifier the broker assigned when we sent an empty one


[View source]
def authenticator : Authenticator | Nil #

[View source]
def authenticator=(authenticator : Authenticator | Nil) #

[View source]
def connect(username : String | Nil = nil, password : String | Nil = nil, keep_alive : Int32 = 60, client_id : String = MQTT.generate_client_id, clean_start : Bool = true, session_expiry_interval : UInt32 | Nil = nil, receive_maximum : UInt16 | Nil = nil, will_flag : Bool = false, will_qos : Int32 | QoS = 0, will_retain : Bool = false, will_topic : String | Nil = nil, will_payload : String | Bytes | Nil = nil, will_delay_interval : UInt32 | Nil = nil, timeout : Time::Span | Nil = @timeout, keep_alive_active : Bool = true) : Connack #

[View source]
def disconnect(send_msg = true, reason : ReasonCode = ReasonCode::Success) : Nil #

[View source]
def disconnect_reason : ReasonCode | Nil #

Why the broker closed the connection, when it said


[View source]
def parse_message(io) #
Description copied from class MQTT::ClientBase

Handles a decoded packet. Implemented per protocol version


[View source]
def ping(timeout : Time::Span | Nil = @timeout) : Nil #
Description copied from class MQTT::ClientBase

Sends whatever this protocol version uses for a liveness check, and waits for the response


[View source]
def publish(topic : String, payload = "", retain : Bool = false, qos : QoS = QoS::FireAndForget, content_type : String | Nil = nil, response_topic : String | Nil = nil, correlation_data : Bytes | Nil = nil, message_expiry_interval : UInt32 | Nil = nil, payload_format_indicator : UInt8 | Nil = nil, user_properties : Enumerable(Tuple(String, String)) | Nil = nil, timeout : Time::Span | Nil = @timeout) #

[View source]
def publish_received(pub : Publish) #

[View source]
def reauthenticate(timeout : Time::Span | Nil = @timeout) : Nil #

Re-authenticates an established connection, MQTT-4.12.1. The broker answers with further challenges and finally an AUTH carrying Success, or drops the connection


[View source]
def server_maximum_packet_size : UInt32 | Nil #

[View source]
def server_maximum_qos : QoS #

[View source]
def server_receive_maximum : UInt16 #

What the broker told us it will accept, from the CONNACK


[View source]
def server_reference : String | Nil #

Where the broker told us to go instead, from a CONNACK or a DISCONNECT


[View source]
def server_retain_available? : Bool #

[View source]
def server_shared_subscriptions_available? : Bool #

[View source]
def server_subscription_identifiers_available? : Bool #

[View source]
def server_topic_alias_maximum : UInt16 #

[View source]
def server_wildcard_available? : Bool #

[View source]
def session_expiry_interval : UInt32 | Nil #

The session expiry the broker settled on, which may differ from ours


[View source]
def subscribe(*topics, qos : QoS = QoS::FireAndForget, no_local : Bool = false, retain_as_published : Bool = false, retain_handling : RetainHandling = RetainHandling::SendAlways, identifier : UInt32 | Nil = nil, timeout : Time::Span | Nil = @timeout, &callback : String, Bytes, Bool -> Nil) #

[View source]
def subscribe(filters : Enumerable(String), callback : Callback, qos : QoS = QoS::FireAndForget, no_local : Bool = false, retain_as_published : Bool = false, retain_handling : RetainHandling = RetainHandling::SendAlways, identifier : UInt32 | Nil = nil, timeout : Time::Span | Nil = @timeout) #

Full form, also used by the block version above


[View source]
def subscriptions : Hash(String, QoS) #

[View source]
def unsubscribe(*topics, timeout : Time::Span | Nil = @timeout) #

[View source]
def use_topic_aliases=(use_topic_aliases : Bool) #

Use topic aliases when the broker offers them. Saves repeating a topic string on every publish; set false to always send the topic


[View source]
def use_topic_aliases? : Bool #

Use topic aliases when the broker offers them. Saves repeating a topic string on every publish; set false to always send the topic


[View source]