本文整理汇总了Python中mqttcli.MqttClient.pubrel方法的典型用法代码示例。如果您正苦于以下问题:Python MqttClient.pubrel方法的具体用法?Python MqttClient.pubrel怎么用?Python MqttClient.pubrel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mqttcli.MqttClient
的用法示例。
在下文中一共展示了MqttClient.pubrel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_013
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import pubrel [as 别名]
def test_013(self):
pub = MqttClient("conformity:{seq}", connect=4)
sub = MqttClient("sub:{seq}", connect=4)
sub.subscribe("/test/022/013/+", qos=2)
pub.publish("/test/022/013/t1", 'hurry', retain=True, qos=1)
msg = sub.recv()
if not isinstance(msg, EventPublish) or \
msg.msg.topic != '/test/022/013/t1' or \
msg.msg.payload != 'hurry' or\
msg.msg.qos != 1 or\
msg.msg.retain:
debug(msg)
return False
# same with empty payload
pub.publish("/test/022/013/t2", 'up', retain=True, qos=2)
pub.pubrel(pub.get_last_mid())
msg = sub.recv()
if not isinstance(msg, EventPublish) or \
msg.msg.topic != '/test/022/013/t2' or \
msg.msg.payload != "up" or\
msg.msg.qos != 2 or\
msg.msg.retain:
debug(msg)
return False
return True
示例2: test_005
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import pubrel [as 别名]
def test_005(self):
sub = MqttClient("sub:{seq}", connect=4)
sub.subscribe("foo/bar", qos=2)
pub = MqttClient("pub:{seq}", connect=4)
ack = pub.publish("foo/bar", env.gen_msg(42), qos=2)
pub.pubrel(ack.mid)
evt = sub.recv()
if not isinstance(evt, EventPublish):
debug(evt)
defer.returnValue(False)
sub.pubrec(evt.msg.mid)
# PUBCOMP not send
sub.destroy(); del sub
if (yield supervisor.count('wave_msgworkers_sup')) != 1:
debug("wrong msgworkers count")
defer.returnValue(False)
# msg worker is destroyed after 5 secs
time.sleep(6)
if (yield supervisor.count('wave_msgworkers_sup')) != 0:
debug("wrong msgworkers count")
defer.returnValue(False)
pub.disconnect()
defer.returnValue(True)
示例3: test_232
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import pubrel [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
示例4: test_203
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import pubrel [as 别名]
def test_203(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", "wootwoot", qos=2, read_response=False)
# PUB PUBREC
evt = pub.recv()
pub.pubrel(pub.get_last_mid(), read_response=False)
# subscr: receiving PUBLISH
evt = sub.recv()
sub.pubrec(evt.msg.mid, read_response=False)
# subscr: receiving PUBREL
evt = sub.recv()
# sending PUBCOMP with wrong pktid
sub.forge(NC.CMD_PUBCOMP, 0, [
('uint16', (evt.mid+10)%65535) # wrong pktid
], send=True)
evt = pub.recv()
# publisher: PUBCOMP never received
if evt is not None:
debug(evt)
return False
pub.disconnect(); sub.disconnect()
return True
示例5: test_006
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import pubrel [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
示例6: test_010
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import pubrel [as 别名]
def test_010(self):
sub = MqttClient("sub:{seq}", connect=4, clean_session=0)
sub.subscribe("foo/+", qos=2)
sub.disconnect()
if (yield supervisor.count('wave_msgworkers_sup')) != 0:
debug("wrong msgworkers count")
defer.returnValue(False)
pub = MqttClient("pub:{seq}", connect=4)
rec = pub.publish("foo/bar", env.gen_msg(42), qos=2)
ack = pub.pubrel(rec.mid)
print ack
if not isinstance(ack, EventPubcomp):
debug(ack)
defer.returnValue(False)
# msg is published to offline storage, msg worker should exit immediately
if (yield supervisor.count('wave_msgworkers_sup')) != 0:
debug("wrong msgworkers count")
defer.returnValue(False)
defer.returnValue(True)