本文整理汇总了Python中azure.servicebus.common.message.Message.partition_key方法的典型用法代码示例。如果您正苦于以下问题:Python Message.partition_key方法的具体用法?Python Message.partition_key怎么用?Python Message.partition_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicebus.common.message.Message
的用法示例。
在下文中一共展示了Message.partition_key方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_not_found
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import partition_key [as 别名]
def test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_not_found(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)
deferred_messages = []
with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
with queue_client.get_sender() as sender:
for i in range(3):
message = Message("Deferred message no. {}".format(i))
message.partition_key = "MyPartitionKey"
sender.send(message)
count = 0
for message in receiver:
deferred_messages.append(message.sequence_number)
print_message(message)
count += 1
message.defer()
assert count == 3
with pytest.raises(ServiceBusError):
deferred = queue_client.receive_deferred_messages([3, 4], mode=ReceiveSettleMode.PeekLock)
with pytest.raises(ServiceBusError):
deferred = queue_client.receive_deferred_messages([5, 6, 7], mode=ReceiveSettleMode.PeekLock)
示例2: test_qsession_by_servicebus_client_browse_messages_client
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import partition_key [as 别名]
def test_qsession_by_servicebus_client_browse_messages_client(live_servicebus_config, partitioned_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)
queue_client = client.get_queue(partitioned_session_queue)
session_id = str(uuid.uuid4())
with queue_client.get_sender(session=session_id) as sender:
for i in range(5):
message = Message("Test message no. {}".format(i))
message.partition_key = "MyPartitionKey"
sender.send(message)
with pytest.raises(ValueError):
messages = queue_client.peek(5)
messages = queue_client.peek(5, session=session_id)
assert len(messages) == 5
assert all(isinstance(m, PeekMessage) for m in messages)
for message in messages:
print_message(message)
with pytest.raises(TypeError):
message.complete()
示例3: test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_client
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import partition_key [as 别名]
def test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_client(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)
deferred_messages = []
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("Deferred message no. {}".format(i))
message.partition_key = "MyPartitionKey"
sender.send(message)
count = 0
for message in receiver:
deferred_messages.append(message.sequence_number)
print_message(message)
count += 1
message.defer()
assert count == 10
deferred = queue_client.receive_deferred_messages(deferred_messages, mode=ReceiveSettleMode.PeekLock)
assert len(deferred) == 10
for message in deferred:
assert isinstance(message, DeferredMessage)
with pytest.raises(ValueError):
message.complete()
with pytest.raises(ValueError):
queue_client.settle_deferred_messages('foo', message)
queue_client.settle_deferred_messages('completed', message)
with pytest.raises(ServiceBusError):
queue_client.receive_deferred_messages(deferred_messages)
示例4: test_pqueue_message_connection_closed
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import partition_key [as 别名]
def test_pqueue_message_connection_closed(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)
with queue_client.get_sender() as sender:
content = str(uuid.uuid4())
message = Message(content)
message.partition_key = "MyPartitionKey"
sender.send(message)
with queue_client.get_receiver() as receiver:
messages = receiver.fetch_next(timeout=10)
assert len(messages) == 1
with pytest.raises(MessageSettleFailed):
messages[0].complete()
示例5: test_pqueue_by_servicebus_client_browse_messages_with_receiver
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import partition_key [as 别名]
def test_pqueue_by_servicebus_client_browse_messages_with_receiver(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(5):
message = Message("Test message no. {}".format(i))
message.partition_key = "MyPartitionKey"
sender.send(message)
messages = receiver.peek(5)
assert len(messages) > 0
assert all(isinstance(m, PeekMessage) for m in messages)
for message in messages:
print_message(message)
with pytest.raises(TypeError):
message.complete()
示例6: test_pqueue_by_servicebus_client_renew_message_locks
# 需要导入模块: from azure.servicebus.common.message import Message [as 别名]
# 或者: from azure.servicebus.common.message.Message import partition_key [as 别名]
def test_pqueue_by_servicebus_client_renew_message_locks(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)
messages = []
locks = 3
with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock, prefetch=10) as receiver:
with queue_client.get_sender() as sender:
for i in range(locks):
message = Message("Test message no. {}".format(i))
message.partition_key = "MyPartitionKey"
sender.send(message)
messages.extend(receiver.fetch_next())
recv = True
while recv:
recv = receiver.fetch_next()
messages.extend(recv)
try:
assert not message.expired
for m in messages:
time.sleep(5)
initial_expiry = m.locked_until
m.renew_lock()
assert (m.locked_until - initial_expiry) >= timedelta(seconds=5)
finally:
messages[0].complete()
messages[1].complete()
time.sleep(30)
with pytest.raises(MessageLockExpired):
messages[2].complete()