本文整理汇总了Python中Message.set_body方法的典型用法代码示例。如果您正苦于以下问题:Python Message.set_body方法的具体用法?Python Message.set_body怎么用?Python Message.set_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.set_body方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_messages_to_python_with_json_message
# 需要导入模块: import Message [as 别名]
# 或者: from Message import set_body [as 别名]
def test_messages_to_python_with_json_message(self):
message_count = 3
# JSON formatted message NOT created by celery
q = self.channel._new_queue(self.queue_name)
message = '{"foo":"bar"}'
for i in range(message_count):
m = Message()
m.set_body(message)
q.write(m)
# Get the messages now
messages = q.get_messages(num_messages=message_count)
# Now convert them to payloads
payloads = self.channel._messages_to_python(
messages, self.queue_name,
)
# We got the same number of payloads back, right?
self.assertEquals(len(payloads), message_count)
# Make sure they're payload-style objects, and body is the same
for p in payloads:
self.assertTrue('properties' in p)
self.assertEqual(p['body'], message)
示例2: _put
# 需要导入模块: import Message [as 别名]
# 或者: from Message import set_body [as 别名]
def _put(self, queue, message, **kwargs):
"""Put message onto queue."""
q = self._new_queue(queue)
m = Message()
m.set_body(dumps(message))
q.write(m)