本文整理汇总了Python中azure.servicebus.common.message.Message.schedule方法的典型用法代码示例。如果您正苦于以下问题:Python Message.schedule方法的具体用法?Python Message.schedule怎么用?Python Message.schedule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicebus.common.message.Message
的用法示例。
在下文中一共展示了Message.schedule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pqueue_schedule_message
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import schedule [as 别名]
def test_pqueue_schedule_message(live_servicebus_config, partitioned_queue):
client = ServiceBusClient(
service_namespace=live_servicebus_config['hostname'],
shared_access_key_name=live_servicebus_config['key_name'],
shared_access_key_value=live_servicebus_config['access_key'],
debug=True)
import uuid
queue_client = client.get_queue(partitioned_queue)
enqueue_time = (datetime.now() + timedelta(minutes=2)).replace(microsecond=0)
with queue_client.get_receiver() as receiver:
with queue_client.get_sender() as sender:
content = str(uuid.uuid4())
message_id = uuid.uuid4()
message = Message(content)
message.properties.message_id = message_id
message.schedule(enqueue_time)
sender.send(message)
messages = receiver.fetch_next(timeout=120)
if messages:
try:
data = str(messages[0])
assert data == content
assert messages[0].properties.message_id == message_id
assert messages[0].scheduled_enqueue_time == enqueue_time
assert messages[0].scheduled_enqueue_time == messages[0].enqueued_time.replace(microsecond=0)
assert len(messages) == 1
finally:
for m in messages:
m.complete()
else:
raise Exception("Failed to receive schdeduled message.")
示例2: test_session_schedule_message
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import schedule [as 别名]
def test_session_schedule_message(live_servicebus_config, session_queue):
client = ServiceBusClient(
service_namespace=live_servicebus_config['hostname'],
shared_access_key_name=live_servicebus_config['key_name'],
shared_access_key_value=live_servicebus_config['access_key'],
debug=True)
import uuid
session_id = str(uuid.uuid4())
queue_client = client.get_queue(session_queue)
enqueue_time = (datetime.now() + timedelta(minutes=2)).replace(microsecond=0)
with queue_client.get_receiver(session=session_id) as receiver:
with queue_client.get_sender(session=session_id) as sender:
content = str(uuid.uuid4())
message_id = uuid.uuid4()
message = Message(content)
message.properties.message_id = message_id
message.schedule(enqueue_time)
sender.send(message)
messages = []
count = 0
while not messages and count < 12:
messages = receiver.fetch_next(timeout=10)
receiver.renew_lock()
count += 1
data = str(messages[0])
assert data == content
assert messages[0].properties.message_id == message_id
assert messages[0].scheduled_enqueue_time == enqueue_time
assert messages[0].scheduled_enqueue_time == messages[0].enqueued_time.replace(microsecond=0)
assert len(messages) == 1