本文整理汇总了Python中amqpstorm.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_message_auto_decode_cache
def test_message_auto_decode_cache(self):
message = Message(body=self.message,
channel=None)
self.assertEqual(self.message, message.body)
message._body = 'invalidate'
self.assertEqual(self.message, message.body)
示例2: test_message_json
def test_message_json(self):
body = '{"key": "value"}'
message = Message(body=body, channel=None)
result = message.json()
self.assertIsInstance(result, dict)
self.assertEqual(result['key'], 'value')
示例3: test_message_auto_decode_cache
def test_message_auto_decode_cache(self):
body = 'Hello World',
message = Message(body=body,
channel=None)
self.assertEqual(body, message.body)
message._body = 'invalidate'
self.assertEqual(body, message.body)
示例4: test_to_dict
def test_to_dict(self):
body = b'Hello World'
message = Message(body=body,
properties={'key': 'value'},
method={'key': 'value'},
channel=None)
result = message.to_dict()
self.assertIsInstance(result, dict)
self.assertEqual(result['body'], body)
示例5: test_to_tuple
def test_to_tuple(self):
body = b'Hello World'
message = Message(body=body,
properties={'key': 'value'},
method={'key': 'value'},
channel=None)
body, channel, method, properties = message.to_tuple()
self.assertEqual(body, body)
self.assertIsInstance(method, dict)
self.assertIsInstance(properties, dict)
self.assertIsNone(channel)
示例6: test_message_to_dict
def test_message_to_dict(self):
body = self.message
properties = {'key': 'value'}
method = {b'alternative': 'value'}
message = Message(body=body,
properties=properties,
method=method,
channel=None)
result = message.to_dict()
self.assertIsInstance(result, dict)
self.assertEqual(result['body'], body)
self.assertEqual(result['properties'], properties)
self.assertEqual(result['method'], method)
示例7: test_message_delivery_mode_two
def test_message_delivery_mode_two(self):
delivery_mode = 2
message = Message.create(None, '')
message.delivery_mode = delivery_mode
self.assertEqual(delivery_mode, message.delivery_mode)
示例8: publish_message
def publish_message(channel, body, queue, expiration="600"):
# Create the message with a expiration (time to live).
message = Message.create(channel, body,
properties={"expiration": expiration})
# Publish the message to a queue.
message.publish(queue)
示例9: test_message_content_type_custom_value
def test_message_content_type_custom_value(self):
content_type = 'application/json'
message = Message.create(None, '')
message.content_type = content_type
self.assertEqual(content_type, message.content_type)
示例10: test_functional_publish_and_change_app_id
def test_functional_publish_and_change_app_id(self):
self.channel.confirm_deliveries()
self.channel.queue.declare(self.queue_name)
message = Message.create(self.channel,
body=self.message)
message.app_id = 'travis-ci'
message.publish(self.queue_name)
message = self.channel.basic.get(self.queue_name, no_ack=True)
# Check original app_id
self.assertEqual(message.app_id, 'travis-ci')
# Assign Property app_id
app_id = 'travis-ci-2'.encode('utf-8')
message.app_id = app_id
# Check that it was set correctly.
self.assertEqual(message.properties['app_id'], app_id)
# Get Property Correlation Id
correlation_id = message.correlation_id
# Publish Message
message.publish(routing_key=self.queue_name)
# Sleep for 0.01s to make sure RabbitMQ has time to catch up.
time.sleep(0.01)
payload = self.channel.basic.get(self.queue_name, no_ack=True)
self.assertEqual(payload.app_id, app_id.decode('utf-8'))
self.assertEqual(payload.correlation_id, correlation_id)
self.assertIsInstance(payload.properties['app_id'], str)
self.assertIsInstance(payload.properties['correlation_id'], str)
示例11: test_message_reply_to_custom_value
def test_message_reply_to_custom_value(self):
reply_to = str(uuid.uuid4())
message = Message.create(None, '')
message.reply_to = reply_to
self.assertEqual(reply_to, message.reply_to)
示例12: test_message_timestamp_custom_value
def test_message_timestamp_custom_value(self):
dt = datetime.now()
message = Message.create(None, '')
message.timestamp = dt
self.assertEqual(dt, message.timestamp)
示例13: test_message_correlation_id_custom_value
def test_message_correlation_id_custom_value(self):
correlation_id = str(uuid.uuid4())
message = Message.create(None, '')
message.correlation_id = correlation_id
self.assertEqual(correlation_id, message.correlation_id)
示例14: test_message_priority_three
def test_message_priority_three(self):
priority = 3
message = Message.create(None, '')
message.priority = priority
self.assertEqual(priority, message.priority)
示例15: test_message_app_id_custom_value
def test_message_app_id_custom_value(self):
app_id = 'my-app'
message = Message.create(None, '')
message.app_id = app_id
self.assertEqual(app_id, message.app_id)