本文整理汇总了Python中azure.servicebus.common.message.Message.renew_lock方法的典型用法代码示例。如果您正苦于以下问题:Python Message.renew_lock方法的具体用法?Python Message.renew_lock怎么用?Python Message.renew_lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicebus.common.message.Message
的用法示例。
在下文中一共展示了Message.renew_lock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pqueue_by_servicebus_client_iter_messages_simple
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import renew_lock [as 别名]
def test_pqueue_by_servicebus_client_iter_messages_simple(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)
queue_client = client.get_queue(partitioned_queue)
with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
with queue_client.get_sender() as sender:
for i in range(10):
message = Message("Iter message no. {}".format(i))
sender.send(message)
count = 0
for message in receiver:
print_message(message)
message.complete()
with pytest.raises(MessageAlreadySettled):
message.complete()
with pytest.raises(MessageAlreadySettled):
message.renew_lock()
count += 1
with pytest.raises(InvalidHandlerState):
next(receiver)
assert count == 10
示例2: test_session_by_conn_str_receive_handler_with_autolockrenew
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import renew_lock [as 别名]
def test_session_by_conn_str_receive_handler_with_autolockrenew(live_servicebus_config, session_queue):
session_id = str(uuid.uuid4())
queue_client = QueueClient.from_connection_string(
live_servicebus_config['conn_str'],
name=session_queue,
debug=True)
with queue_client.get_sender(session=session_id) as sender:
for i in range(10):
message = Message("{}".format(i))
sender.send(message)
renewer = AutoLockRenew()
messages = []
with queue_client.get_receiver(session=session_id, idle_timeout=5, mode=ReceiveSettleMode.PeekLock, prefetch=10) as session:
renewer.register(session, timeout=60)
print("Registered lock renew thread", session.locked_until, datetime.now())
with pytest.raises(SessionLockExpired):
for message in session:
if not messages:
print("Starting first sleep")
time.sleep(40)
print("First sleep {}".format(session.locked_until - datetime.now()))
assert not session.expired
with pytest.raises(TypeError):
message.expired
assert message.locked_until is None
with pytest.raises(TypeError):
message.renew_lock()
assert message.lock_token is None
message.complete()
messages.append(message)
elif len(messages) == 1:
print("Starting second sleep")
time.sleep(40)
print("Second sleep {}".format(session.locked_until - datetime.now()))
assert session.expired
assert isinstance(session.auto_renew_error, AutoLockRenewTimeout)
try:
message.complete()
raise AssertionError("Didn't raise SessionLockExpired")
except SessionLockExpired as e:
assert isinstance(e.inner_exception, AutoLockRenewTimeout)
messages.append(message)
renewer.shutdown()
assert len(messages) == 2