当前位置: 首页>>代码示例>>Python>>正文


Python MqttClient.unsubscribe方法代码示例

本文整理汇总了Python中mqttcli.MqttClient.unsubscribe方法的典型用法代码示例。如果您正苦于以下问题:Python MqttClient.unsubscribe方法的具体用法?Python MqttClient.unsubscribe怎么用?Python MqttClient.unsubscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mqttcli.MqttClient的用法示例。


在下文中一共展示了MqttClient.unsubscribe方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_003

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_003(self):
        sub = MqttClient("sub:{seq}", connect=4)
        sub.subscribe('a/b', qos=1)

        pub = MqttClient("pub:{seq}", connect=4)
        msg = gen_msg()
        pub.publish('a/b', payload=msg, qos=1)
        pub.recv()

        e = sub.recv()
        if not isinstance(e, EventPublish) or \
                e.msg.payload != msg or \
                e.msg.qos     != 1:
            debug('failing event: {0}'.format(e))
            return False

        # send PUBACK
        sub.puback(e.msg.mid)

        puback_evt = pub.recv()
        # PUBACK mid == PUBLISH mid
        # validating [MQTT-2.3.1-6]
        if not isinstance(puback_evt, EventPuback) or \
                puback_evt.mid != pub.get_last_mid():
            debug('failing event: {0}'.format(puback_evt))
            return False

        sub.unsubscribe('a/b')
        sub.disconnect(); pub.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:32,代码来源:006_qos1.py

示例2: _pubsub

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def _pubsub(self, pubtopic, subtopic, match):
        msg = gen_msg()

        sub = MqttClient("sub:{seq}", connect=4)
        suback_evt = sub.subscribe(subtopic, 0)
        if not isinstance(suback_evt, EventSuback) or \
                suback_evt.mid != sub.get_last_mid() or \
                suback_evt.granted_qos[0] != 0:
            if match: debug("failed to subscribe: {0}".format(suback_evt))
            return False

        pub = MqttClient("pub:{seq}", connect=4)
        pub.publish(pubtopic, msg)
        pub.disconnect()

        e = sub.recv()
        unsuback_evt = sub.unsubscribe(subtopic)
        if not isinstance(unsuback_evt, EventUnsuback) or \
                unsuback_evt.mid != sub.get_last_mid():
            if match: debug("failed to unsubscribe: {0}".format(unsuback_evt))
            return False

        sub.disconnect()
        #print e, e.msg.topic, e.msg.payload
        if not isinstance(e, EventPublish) or \
                e.msg.topic   != pubtopic or \
                e.msg.payload != msg:
            if match: debug("invalid received msg: {0}".format(e))
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:33,代码来源:002_pubsub.py

示例3: test_232

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_232(self):
        pub = MqttClient("conformity-pub:{seq}", connect=4)
        sub = MqttClient("conformity-sub:{seq}", connect=4)

        sub.subscribe("foo/bar", qos=2)
        pub.publish("foo/bar", "grrr", qos=2)                # receive PUBREC as response
        pub.pubrel(pub.get_last_mid(), read_response=False) # triggers message delivery

        evt = sub.recv()
        if not isinstance(evt, EventPublish) or evt.msg.payload != "grrr":
            debug(evt)
            return False

        ack = sub.unsubscribe("foo/bar")
        if not isinstance(ack, EventUnsuback):
            debug(ack)
            return False

        rel = sub.pubrec(evt.msg.mid)
        if not isinstance(rel, EventPubrel):
            debug(rel)
            return False

        sub.pubcomp(evt.msg.mid)
        comp = pub.recv()
        if not isinstance(comp, EventPubcomp):
            debug(comp)
            return False

        pub.disconnect(); sub.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:33,代码来源:020_v311.py

示例4: test_231

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_231(self):
        pub = MqttClient("conformity-pub:{seq}", connect=4)
        sub = MqttClient("conformity-sub:{seq}", connect=4)

        sub.subscribe("foo/bar", qos=1)
        pub.publish("foo/bar", "grrr", qos=1)

        evt = sub.recv()
        if not isinstance(evt, EventPublish) or evt.msg.payload != "grrr":
            debug(evt)
            return False

        ack = sub.unsubscribe("foo/bar")
        if not isinstance(ack, EventUnsuback):
            debug(ack)
            return False

        sub.puback(evt.msg.mid)
        ack2 = pub.recv()
        if not isinstance(ack2, EventPuback):
            debug(ack2)
            return False

        pub.disconnect(); sub.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:27,代码来源:020_v311.py

示例5: test_221

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_221(self):
        c = MqttClient("conformity:{seq}", connect=4)
        ack = c.unsubscribe("foo/bar")
        if not isinstance(ack, EventUnsuback):
            debug(ack)
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:10,代码来源:020_v311.py

示例6: test_006

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_006(self):
        sub = MqttClient("sub:{seq}", connect=4)
        sub.subscribe('a/b', qos=1)

        pub = MqttClient("pub:{seq}", connect=4)
        msg = gen_msg()
        pub.publish('a/b', payload=msg, qos=1)
        pub.recv()

        e = sub.recv()
        if not isinstance(e, EventPublish) or \
                e.msg.payload != msg or \
                e.msg.qos     != 1:
            debug('failing event: {0}'.format(e))
            return False

        # send PUBREL (! ERROR: not a QOS 2 message)
        sub.pubrec(e.msg.mid)

        puback_evt = pub.recv()
        if not puback_evt is None:
            debug('failing event: {0}'.format(puback_evt))
            return False

        # unexpected PUBREL
        sub.pubrel(e.msg.mid)
        puback_evt = pub.recv()
        if not puback_evt is None:
            debug('failing event: {0}'.format(puback_evt))
            return False

        # unexpected PUBCOMP
        sub.pubcomp(e.msg.mid)
        puback_evt = pub.recv()
        if not puback_evt is None:
            debug('failing event: {0}'.format(puback_evt))
            return False

        sub.unsubscribe('a/b')

        sub.disconnect()
        pub.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:45,代码来源:006_qos1.py

示例7: test_022

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_022(self):
        sub = MqttClient("sub:{seq}", connect=4)
        sub.subscribe('a/b', qos=0)

        pub = MqttClient("pub:{seq}", connect=4)
        # published with qos 0
        msg = gen_msg()
        pub.publish('a/b', payload=msg, qos=1)
        pub.disconnect()

        e = sub.recv()
        sub.unsubscribe('a/b')
        sub.disconnect()

        if not isinstance(e, EventPublish) or \
                e.msg.payload != msg or \
                e.msg.qos     != 0:
            debug('failing event: {0}'.format(e))
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:23,代码来源:006_qos1.py

示例8: test_012

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_012(self):
        """
        """
        v = yield exometer.value('wave.subscriptions')
        ref_val = v['value']

        c = MqttClient("metrics:{seq}", connect=4)
        c.subscribe('foo/bar', qos=0)

        v = yield exometer.value('wave.subscriptions')
        if v['value'] != ref_val+1:
            debug("{0}, {1}".format(v, ref_val))
            defer.returnValue(False)

        c.unsubscribe('foo/bar')
        v = yield exometer.value('wave.subscriptions')
        if v['value'] != ref_val:
            debug("{0}, {1}".format(v, ref_val))
            defer.returnValue(False)

        c.disconnect()
        defer.returnValue(True)
开发者ID:gbour,项目名称:wave,代码行数:24,代码来源:033_metrics.py

示例9: test_230

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_230(self):
        pub = MqttClient("conformity-pub:{seq}", connect=4)
        sub = MqttClient("conformity-sub:{seq}", connect=4)

        sub.subscribe("foo/bar", qos=0)
        pub.publish("foo/bar", "grrr", qos=0)

        evt = sub.recv()
        if not isinstance(evt, EventPublish) or evt.msg.payload != "grrr":
            debug(evt)
            return False

        sub.unsubscribe("foo/bar")
        pub.publish("foo/bar", "grrr bis", qos=0)

        evt = sub.recv()
        if evt is not None:
            debug(evt)
            return False

        pub.disconnect(); sub.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:24,代码来源:020_v311.py

示例10: test_255

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_255(self):
        c = MqttClient("conformity:{seq}", connect=4)
        c.subscribe("", qos=0)

        if c.conn_is_alive():
            debug("connection still alive")
            return False

        c = MqttClient("conformity:{seq}", connect=4)
        c.unsubscribe("")

        if c.conn_is_alive():
            debug("connection still alive")
            return False

        c = MqttClient("conformity:{seq}", connect=4)
        c.publish("", "", qos=0)

        if c.conn_is_alive():
            debug("connection stil alive")
            return False

        return True
开发者ID:gbour,项目名称:wave,代码行数:25,代码来源:020_v311.py

示例11: test_010

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_010(self):
        c = MqttClient("reg:{seq}", connect=4)

        evt = c.subscribe("/foo/bar", qos=0)
        # validating [MQTT-2.3.1-7]
        if not isinstance(evt, EventSuback) or evt.mid != c.get_last_mid():
            return False

        evt = c.unsubscribe("/foo/bar")
        # validating [MQTT-2.3.1-7]
        if not isinstance(evt, EventUnsuback) or evt.mid != c.get_last_mid():
            return False

        c.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:17,代码来源:001_basics.py

示例12: test_002

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import unsubscribe [as 别名]
    def test_002(self):
        pub = MqttClient("publisher:{seq}")
        evt = pub.connect()
        if not isinstance(evt, EventConnack) or evt.ret_code != 0:
            debug(evt); return False

        ctrl = MqttClient("control-sample:{seq}")
        evt = ctrl.connect()
        if not isinstance(evt, EventConnack) or evt.ret_code != 0:
            debug(evt); return False

        evt = ctrl.subscribe("/test/qos/0", qos=0)
        if not isinstance(evt, EventSuback):
            debug(evt); return False


        ###
        dummyid = "dummy:{0}".format(random.randint(0,9999))
        dummy = MqttClient(dummyid)
        evt = dummy.connect(clean_session=0)
        if not isinstance(evt, EventConnack) or evt.ret_code != 0:
            debug(evt); return False

        evt = dummy.subscribe("/test/qos/0", qos=0)
        if not isinstance(evt, EventSuback):
            debug(evt); return False


        # 1. sent qos0, 1, 2 messages; check reception
        if not self.pubsub((pub, ctrl, dummy), clbs={
                    'checkrecv': lambda evt, msg: isinstance(evt, EventPublish) and evt.msg.payload == msg
                }):
            return False

        # 2. disconnecting (properly) dummmy; then reconnects
        dummy.disconnect(); del(dummy)
        # be sure dummy client disconnection in fully complete on broker side before going further
        time.sleep(1)

        ## publish message
        msg = gen_msg(10)
        pub.publish("/test/qos/0", payload=msg)


        ## reconnects, without explicitly subscribing topic
        dummy = MqttClient(dummyid)
        evt = dummy.connect(clean_session=0)
        if not isinstance(evt, EventConnack) or evt.ret_code != 0:
            debug(evt); return False


        ## checking message is not received by dummy
        evt = ctrl.recv()
        if not isinstance(evt, EventPublish) or evt.msg.payload != msg:
            debug(evt); return False

        evt = dummy.recv()
        if not isinstance(evt, EventPublish) or evt.msg.payload != msg:
            debug(evt); return False

        ## dummy resubscribe, check we receive messages
        #evt = dummy.do("subscribe", "/test/qos/0", 0)
        #if not isinstance(evt, EventSuback):
        #    return False

        ## send test message
        if not self.pubsub((pub, ctrl, dummy), clbs={
                    'checkrecv': lambda evt, msg: evt is not None and evt.msg.payload == msg
                }):
            return False

        # cleanup
        pub.disconnect()
        ctrl.disconnect()
        dummy.unsubscribe("/test/qos/0")
        dummy.disconnect()

        return True
开发者ID:gbour,项目名称:wave,代码行数:80,代码来源:005_connect_flags.py


注:本文中的mqttcli.MqttClient.unsubscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。