Пример #1
0
    def unsubscribe(self, topic):
        """Unsubscribe from a topic filter (async).

        The client sends an UNSUBSCRIBE packet, and the server responds with an UNSUBACK.

        Args:
            topic (str): Unsubscribe from this topic filter.

        Returns:
            Tuple[concurrent.futures.Future, int]: Tuple containing a Future and
            the ID of the UNSUBSCRIBE packet. The Future completes when an
            UNSUBACK is received from the server. If successful, the Future
            will contain a dict with the following members:

            * ['packet_id'] (int): ID of the UNSUBSCRIBE packet being acknowledged.
        """
        future = Future()
        packet_id = 0

        def unsuback(packet_id, error_code):
            if error_code != 0:
                future.set_exception(awscrt.exceptions.from_code(error_code))
            else:
                future.set_result(dict(packet_id=packet_id))

        try:
            packet_id = _awscrt.mqtt_client_connection_unsubscribe(
                self._binding, topic, unsuback)

        except Exception as e:
            future.set_exception(e)

        return future, packet_id
Пример #2
0
    def unsubscribe(self, topic):
        future = Future()
        packet_id = 0

        def unsuback(packet_id):
            future.set_result(dict(packet_id=packet_id))

        try:
            packet_id = _awscrt.mqtt_client_connection_unsubscribe(
                self._binding, topic, unsuback)

        except Exception as e:
            future.set_exception(e)

        return future, packet_id