本文整理汇总了Python中domogik.mq.message.MQMessage.set方法的典型用法代码示例。如果您正苦于以下问题:Python MQMessage.set方法的具体用法?Python MQMessage.set怎么用?Python MQMessage.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domogik.mq.message.MQMessage
的用法示例。
在下文中一共展示了MQMessage.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _on_message
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import set [as 别名]
def _on_message(self, msg):
"""Helper method called on message receive.
msg is a list w/ the message parts
"""
# 1st part is empty
msg.pop(0)
# 2nd part is protocol version
# TODO: version check
proto = msg.pop(0)
# 3rd part is message type
msg_type = msg.pop(0)
# XXX: hardcoded message types!
# any message resets the liveness counter
self.need_handshake = False
self.curr_liveness = self.HB_LIVENESS
if msg_type == b'\x05': # disconnect
self.curr_liveness = 0 # reconnect will be triggered by hb timer
elif msg_type == b'\x02': # request
# remaining parts are the user message
envelope, msg = split_address(msg)
envelope.append(b'')
envelope = [ b'', self._proto_version, b'\x03'] + envelope # REPLY
self.envelope = envelope
mes = MQMessage()
mes.set(msg)
self.on_mdp_request(mes)
else:
# invalid message
# ignored
pass
return
示例2: request
# 需要导入模块: from domogik.mq.message import MQMessage [as 别名]
# 或者: from domogik.mq.message.MQMessage import set [as 别名]
def request(self, service, msg, timeout=None):
"""Send the given message.
:param msg: message parts to send.
:type msg: list of str
:param timeout: time to wait in milliseconds.
:type timeout: int
:rtype : message parts
"""
ret = self.rawrequest( service, msg, timeout)
msg = None
if ret:
msg = MQMessage()
msg.set(ret)
return msg