This is the highest abstraction of the package and represents the whole MQTT Broker. It’s main roles are handling incoming connections, keeping tabs for the known client sessions and dispatching messages based on subscription matching.
Register a client to the Broker.
Parameters: | client (MQTTClient) – A broker.client.MQTTClient instance. |
---|
Broadcasts a message to all clients with matching subscriptions, respecting the subscription QoS.
Parameters: | msg (Publish) – A broker.messages.Publish instance. |
---|
Configures the last will message options for a given client on its connect message. Both the client and the connect message must point to the same client uid.
Parameters: |
|
---|
Disconnects a MQTT client. Can be safely called without checking if the client is connected.
Parameters: | client (MQTTClient) – The MQTTClient to be disconnect |
---|
Dispatches a message to a client based on its subscriptions. It is safe to call this method without checking if the client has matching subscriptions.
Parameters: |
|
---|
Enqueues all retained messages matching the subscription_mask to be sent to the client.
Parameters: |
|
---|
Returns a known MQTTClient instance that has the same uid defined on the Connect message.
Caution
If the connect message defines the usage of a clean session, this method will clear any previous session matching this client ID and automatically return None
Parameters: | Connect (connect_msg) – A connect message that specifies the client. |
---|
Handles an incoming publish. This method is normally called by the clients a mechanism of notifying the server that there is a new message to be processed. The processing itself consists of retaining the message according with the msg.retain flag and broadcasting it to the subscribers.
Parameters: | msg (Publish) – The Publish message to be processed. |
---|
This coroutine is called by the Tornado loop whenever it receives a incoming connection. The server resolves the first message sent, checks if it’s a CONNECT frame and configures the client accordingly.
Parameters: |
|
---|
Removes a client from the know clients list. It’s safe to call this method without checking if the client is already known.
Parameters: | client (MQTTClient) – A broker.client.MQTTClient instance; |
---|
Caution
It won’t force client disconnection during the process, which can result in a lingering client in the Tornado loop.
Objects of this class encapsulate and abstract all aspects of a given client. A MQTTClient object may refer to a live, connected, client or a known client which albeit disconnected had the clean_sessions flag set to false and, thus, is kept by the server as an end point for routed messages.
One may call self.is_connected() to check whether is there a connected client or not.
Parameters: |
|
---|
Callback called when the connection times out. Ensures clearing the self.connected event and processing the self.disconnect() method.
Callback called when the stream closes. Ensures clearing the self.connected event and processing the self.disconnect() method.
This coroutinte fetches the message raw data from self.incoming_queue, parses it into the corresponding message object (an instance of one of the broker.messages.BaseMQTTMessage subclasses) and passes it to the self.incoming_transaction_manager to be processed.
It is started by calling self.start() and stops upon client disconnection.
This coroutinte fetches the message raw data from self.outgoing_queue, parses it into the corresponding message object (an instance of one of the broker.messages.BaseMQTTMessage subclasses) and passes it to the self.outgoing_transaction_manager to be processed.
It is started by calling self.start() and stops upon client disconnection.
Configures a message to be send as the client’s last will. This message will be send when the connected is disconnected by a connection timeout, protocol error or an unexpected disconnection.
Parameters: |
|
---|
An toro.Event instance that is set whenever the client is connected and clear on disconnection. It’s safe to wait on this property before stream related operations.
Closes the socket and disconnects the client. If self.clean_session is set, ensures that the incoming and outgoing queues are cleared and calls the server client removing routine.
Hint
It’s safe to call this function without checking whether the connection is open or not.
Dispatches a Publish message to the server for further processing, ie. delivering it to the appropriate subscribers.
Parameters: | pub_msg (Publish) – A broker.messages.Publish instance. |
---|
Matches the msg.topic against all the current subscriptions and returns a list containing the QoS level for each matched subscription.
Parameters: | msg (Publish) – A MQTT valid message. |
---|---|
Return type: | tuple |
Returns: | A list of QoS levels, ie [0, 0, 1, 2, 0, 2] |
Matches the msg.topic against a single subscription defined by the subscription mask and returns the QoS level on which the message should be delivered.
Parameters: |
|
---|---|
Returns: | QoS Level or None, in case it doesn’t match. |
Checks if a client has a pending last will message and dispatches it for server processing.
Puts a publish packet on the self.outgoing_queue to be sent to the client.
Parameters: | msg (Publish) – The message to be set or a iterable of its bytes. |
---|
Starts the client fetching, processing and dispatching routines. Should be called after object instantiation or a self.update_connection() call.
The following coroutines are started:
- self._process_incoming_messages()
- self._process_outgoing_messages()
Subscribes the client to a topic or wildcarded mask at the informed QoS level. Calling this method also signalizes the server to enqueue the matching retained messages.
When called for a (subscripition_mask, qos) pair for which the client has already a subscription it will silently ignore the command and return a suback.
Parameters: |
|
---|---|
Return type: | int |
Returns: | The granted QoS level (0, 1 or 2) or 0x80 for failed subscriptions. |
Unsubscribes the client from each topic in topics. Safely ignores topics which the client is not subscribed to.
Parameters: | topics (iterable) – An iterable of MQTT valid topic strings. |
---|
Updates the internal attributes.
Parameters: |
|
---|