本文整理匯總了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)