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


Python MqttClient.puback方法代码示例

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


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

示例1: test_003

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import puback [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: test_030

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import puback [as 别名]
    def test_030(self):
        retain = MqttClient("retain:{seq}", connect=4)
        sub    = MqttClient("subscr:{seq}", connect=4)

        msg = {'topic': "baby/ma/ma", 'payload': "The mother of your child(ren)", 'retain': True,
                'qos': 1}
        retain.publish(**msg)

        sub.subscribe("baby/ma/+", qos=1, read_response=False)

        pubevt = None
        while True:
            evt = sub.recv()
            if isinstance(evt, EventSuback): continue
            if isinstance(evt, EventPublish) and\
                    evt.msg.qos == 1 and\
                    evt.msg.retain and\
                    evt.msg.topic == msg['topic'] and\
                    evt.msg.payload == msg['payload']:
                pubevt = evt; continue

            break

        if pubevt is None:
            debug("message not received")
            return False
        sub.puback(mid=pubevt.msg.mid)

        retain.disconnect(); sub.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:32,代码来源:022_retain.py

示例3: test_231

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import puback [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

示例4: test_005

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import puback [as 别名]
    def test_005(self):
        monitor = MqttClient("monitor:{seq}", connect=4)
        # NOTE: '/' prefix skips $ messages
        # TODO: remove it when '$' filter will be impl.
        monitor.subscribe("/#", qos=2)

        client  = MqttClient("rabbit:{seq}") # no keepalive
        will    = {'topic': '/node/disconnect', 'message': client.clientid(), 'qos': 1}
        client.connect(version=4, will=will)
        client.socket_close()

        evt = monitor.recv()
        if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \
                evt.msg.payload != will['message'] or \
                evt.msg.qos != 1:
            debug(evt)
            return False

        monitor.puback(evt.msg.mid)
        monitor.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:23,代码来源:021_lastwill.py

示例5: test_003

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

        pub = MqttClient("pub:{seq}", connect=4)
        pub.publish("foo/bar", env.gen_msg(42), qos=1)

        evt1 = sub.recv()
        evt2 = sub2.recv()

        sub.destroy(); del sub

        if (yield supervisor.count('wave_msgworkers_sup')) != 1:
            debug("wrong msgworkers count")
            defer.returnValue(False)

        # sub removed, sub2 still alive
        time.sleep(6)
        if (yield supervisor.count('wave_msgworkers_sup')) != 1:
            debug("wrong msgworkers count")
            defer.returnValue(False)

        # sub2 still alive
        time.sleep(6)
        if (yield supervisor.count('wave_msgworkers_sup')) != 1:
            debug("wrong msgworkers count")
            defer.returnValue(False)

        # msg worker is destroyed after 5 secs
        sub2.puback(evt2.msg.mid)
        if (yield supervisor.count('wave_msgworkers_sup')) != 0:
            debug("wrong msgworkers count")
            defer.returnValue(False)

        pub.disconnect()
        defer.returnValue(True)
开发者ID:gbour,项目名称:wave,代码行数:40,代码来源:031_partial_delivery.py

示例6: test_031

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import puback [as 别名]
    def test_031(self):
        sub = MqttClient("sub:{seq}", connect=4)
        ack = sub.subscribe_multi([('foo/+', 1), ('foo/#', 1)])
        debug("subscribe_multi response: {0}".format(ack))

        pub = MqttClient("pub:{seq}", connect=4)
        pub.publish("foo/bar", gen_msg(42), qos=1)

        evt = sub.recv()
        if not isinstance(evt, EventPublish) or\
                evt.msg.topic != 'foo/bar' or\
                evt.msg.qos   != 1:
            debug('failing event: {0}'.format(evt))
            return False
        sub.puback(evt.msg.mid, read_response=False)

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

        # receive 2d publish
        evt = sub.recv()
        if not isinstance(evt, EventPublish) or\
                evt.msg.topic != 'foo/bar' or\
                evt.msg.qos   != 1:
            debug('failing event: {0}'.format(evt))
            return False
        sub.puback(evt.msg.mid)

        evt = pub.recv()
        if not isinstance(evt, EventPuback):
            debug('failing event: {0}'.format(evt))
            return False

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


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