async def test_sb_client_incorrect_queue_conn_str_async( self, servicebus_queue_authorization_rule_connection_string, servicebus_queue, wrong_queue, **kwargs): client = ServiceBusClient.from_connection_string( servicebus_queue_authorization_rule_connection_string) async with client: # Validate that the wrong sender/receiver queues with the right credentials fail. with pytest.raises(ValueError): async with client.get_queue_sender(wrong_queue.name) as sender: await sender.send_messages(ServiceBusMessage("test")) with pytest.raises(ValueError): async with client.get_queue_receiver( wrong_queue.name) as receiver: messages = await receiver.receive_messages( max_message_count=1, max_wait_time=1) # But that the correct ones work. async with client.get_queue_sender( servicebus_queue.name) as sender: await sender.send_messages(ServiceBusMessage("test")) async with client.get_queue_receiver( servicebus_queue.name) as receiver: messages = await receiver.receive_messages(max_message_count=1, max_wait_time=1) # Now do the same but with direct connstr initialization. with pytest.raises(ValueError): async with ServiceBusSender._from_connection_string( servicebus_queue_authorization_rule_connection_string, queue_name=wrong_queue.name, ) as sender: await sender.send_messages(ServiceBusMessage("test")) with pytest.raises(ValueError): async with ServiceBusReceiver._from_connection_string( servicebus_queue_authorization_rule_connection_string, queue_name=wrong_queue.name, ) as receiver: messages = await receiver.receive_messages( max_message_count=1, max_wait_time=1) async with ServiceBusSender._from_connection_string( servicebus_queue_authorization_rule_connection_string, queue_name=servicebus_queue.name, ) as sender: await sender.send_messages(ServiceBusMessage("test")) async with ServiceBusReceiver._from_connection_string( servicebus_queue_authorization_rule_connection_string, queue_name=servicebus_queue.name, ) as receiver: messages = await receiver.receive_messages(max_message_count=1, max_wait_time=1)
async def example_create_servicebus_receiver_async(): servicebus_client = example_create_servicebus_client_async() # [START create_servicebus_receiver_from_conn_str_async] import os from azure.servicebus.aio import ServiceBusReceiver servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] queue_receiver = ServiceBusReceiver.from_connection_string( conn_str=servicebus_connection_str, queue_name=queue_name) # [END create_servicebus_receiver_from_conn_str_async] # [START create_servicebus_receiver_async] import os from azure.servicebus.aio import ServiceBusReceiver, ServiceBusSharedKeyCredential fully_qualified_namespace = os.environ[ 'SERVICE_BUS_FULLY_QUALIFIED_NAMESPACE'] shared_access_policy = os.environ['SERVICE_BUS_SAS_POLICY'] shared_access_key = os.environ['SERVICE_BUS_SAS_KEY'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] queue_receiver = ServiceBusReceiver( fully_qualified_namespace=fully_qualified_namespace, credential=ServiceBusSharedKeyCredential(shared_access_policy, shared_access_key), queue_name=queue_name) # [END create_servicebus_receiver_async] # [START create_servicebus_receiver_from_sb_client_async] import os from azure.servicebus.aio import ServiceBusClient servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] servicebus_client = ServiceBusClient.from_connection_string( conn_str=servicebus_connection_str) async with servicebus_client: queue_receiver = servicebus_client.get_queue_receiver( queue_name=queue_name) # [END create_servicebus_receiver_from_sb_client_async] # [START create_subscription_receiver_from_sb_client_async] import os from azure.servicebus import ServiceBusClient servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] topic_name = os.environ["SERVICE_BUS_TOPIC_NAME"] subscription_name = os.environ["SERVICE_BUS_SUBSCRIPTION_NAME"] servicebus_client = ServiceBusClient.from_connection_string( conn_str=servicebus_connection_str) async with servicebus_client: subscription_receiver = servicebus_client.get_subscription_receiver( topic_name=topic_name, subscription_name=subscription_name, ) # [END create_subscription_receiver_from_sb_client_async] return queue_receiver
async def example_create_servicebus_receiver_async(): servicebus_client = example_create_servicebus_client_async() # [START create_servicebus_receiver_from_conn_str_async] import os from azure.servicebus.aio import ServiceBusReceiver servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] queue_receiver = ServiceBusReceiver._from_connection_string( conn_str=servicebus_connection_str, queue_name=queue_name) # [END create_servicebus_receiver_from_conn_str_async] # [START create_queue_deadletter_receiver_from_sb_client_async] import os from azure.servicebus import SubQueue from azure.servicebus.aio import ServiceBusClient servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] servicebus_client = ServiceBusClient.from_connection_string( conn_str=servicebus_connection_str) async with servicebus_client: queue_receiver = servicebus_client.get_queue_receiver( queue_name=queue_name, sub_queue=SubQueue.DeadLetter) # [END create_queue_deadletter_receiver_from_sb_client_async] # [START create_servicebus_receiver_from_sb_client_async] import os from azure.servicebus.aio import ServiceBusClient servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] servicebus_client = ServiceBusClient.from_connection_string( conn_str=servicebus_connection_str) async with servicebus_client: queue_receiver = servicebus_client.get_queue_receiver( queue_name=queue_name) # [END create_servicebus_receiver_from_sb_client_async] # [START create_subscription_deadletter_receiver_from_sb_client_async] import os from azure.servicebus import SubQueue from azure.servicebus.aio import ServiceBusClient servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] topic_name = os.environ["SERVICE_BUS_TOPIC_NAME"] subscription_name = os.environ["SERVICE_BUS_SUBSCRIPTION_NAME"] servicebus_client = ServiceBusClient.from_connection_string( conn_str=servicebus_connection_str) async with servicebus_client: subscription_receiver = servicebus_client.get_subscription_receiver( topic_name=topic_name, subscription_name=subscription_name, sub_queue=SubQueue.DeadLetter) # [END create_subscription_deadletter_receiver_from_sb_client_async] # [START create_subscription_receiver_from_sb_client_async] import os from azure.servicebus.aio import ServiceBusClient servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] topic_name = os.environ["SERVICE_BUS_TOPIC_NAME"] subscription_name = os.environ["SERVICE_BUS_SUBSCRIPTION_NAME"] servicebus_client = ServiceBusClient.from_connection_string( conn_str=servicebus_connection_str) async with servicebus_client: subscription_receiver = servicebus_client.get_subscription_receiver( topic_name=topic_name, subscription_name=subscription_name, ) # [END create_subscription_receiver_from_sb_client_async] return queue_receiver