Exemplo n.º 1
0
    async def test_subscription_by_sas_token_credential_conn_str_send_basic(
            self, servicebus_namespace, servicebus_namespace_key_name,
            servicebus_namespace_primary_key, servicebus_topic,
            servicebus_subscription, **kwargs):
        fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net'
        async with ServiceBusClient(
                fully_qualified_namespace=fully_qualified_namespace,
                credential=ServiceBusSharedKeyCredential(
                    policy=servicebus_namespace_key_name,
                    key=servicebus_namespace_primary_key),
                logging_enable=False) as sb_client:

            async with sb_client.get_topic_sender(
                    topic_name=servicebus_topic.name) as sender:
                message = Message(b"Sample topic message")
                await sender.send_messages(message)

            async with sb_client.get_subscription_receiver(
                    topic_name=servicebus_topic.name,
                    subscription_name=servicebus_subscription.name,
                    max_wait_time=5) as receiver:
                count = 0
                async for message in receiver:
                    count += 1
                    await message.complete()
            assert count == 1
Exemplo n.º 2
0
    async def test_async_mgmt_queue_list_with_negative_credential(
            self, servicebus_namespace, servicebus_namespace_key_name,
            servicebus_namespace_primary_key):
        # invalid_conn_str = 'Endpoint=sb://invalid.servicebus.windows.net/;SharedAccessKeyName=invalid;SharedAccessKey=invalid'
        # mgmt_service = ServiceBusManagementClient.from_connection_string(invalid_conn_str)
        # with pytest.raises(ServiceRequestError):
        #     await async_pageable_to_list(mgmt_service.list_queues())

        invalid_conn_str = 'Endpoint=sb://{}.servicebus.windows.net/;SharedAccessKeyName=invalid;SharedAccessKey=invalid'.format(
            servicebus_namespace.name)
        mgmt_service = ServiceBusManagementClient.from_connection_string(
            invalid_conn_str)
        with pytest.raises(HttpResponseError):
            await async_pageable_to_list(mgmt_service.list_queues())

        # fully_qualified_namespace = 'invalid.servicebus.windows.net'
        # mgmt_service = ServiceBusManagementClient(
        #     fully_qualified_namespace,
        #     credential=ServiceBusSharedKeyCredential(servicebus_namespace_key_name, servicebus_namespace_primary_key)
        # )
        # with pytest.raises(ServiceRequestError):
        #     await async_pageable_to_list(mgmt_service.list_queues())

        fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net'
        mgmt_service = ServiceBusManagementClient(
            fully_qualified_namespace,
            credential=ServiceBusSharedKeyCredential("invalid", "invalid"))
        with pytest.raises(HttpResponseError):
            await async_pageable_to_list(mgmt_service.list_queues())
Exemplo n.º 3
0
    async def test_async_mgmt_queue_list_basic(
            self, servicebus_namespace_connection_string, servicebus_namespace,
            servicebus_namespace_key_name, servicebus_namespace_primary_key):
        mgmt_service = ServiceBusManagementClient.from_connection_string(
            servicebus_namespace_connection_string)
        await clear_queues(mgmt_service)
        queues = await async_pageable_to_list(mgmt_service.list_queues())
        assert len(queues) == 0
        await mgmt_service.create_queue("test_queue")
        queues = await async_pageable_to_list(mgmt_service.list_queues())
        assert len(queues) == 1 and queues[0].name == "test_queue"
        await mgmt_service.delete_queue("test_queue")
        queues = await async_pageable_to_list(mgmt_service.list_queues())
        assert len(queues) == 0

        fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net'
        mgmt_service = ServiceBusManagementClient(
            fully_qualified_namespace,
            credential=ServiceBusSharedKeyCredential(
                servicebus_namespace_key_name,
                servicebus_namespace_primary_key))
        queues = await async_pageable_to_list(mgmt_service.list_queues())
        assert len(queues) == 0
        await mgmt_service.create_queue("test_queue")
        queues = await async_pageable_to_list(mgmt_service.list_queues())
        assert len(queues) == 1 and queues[0].name == "test_queue"
        await mgmt_service.delete_queue("test_queue")
        queues = await async_pageable_to_list(mgmt_service.list_queues())
        assert len(queues) == 0
    async def test_async_mgmt_queue_list_basic(
            self, servicebus_namespace_connection_string, servicebus_namespace,
            servicebus_namespace_key_name, servicebus_namespace_primary_key):
        sb_mgmt_client = ServiceBusManagementClient.from_connection_string(
            servicebus_namespace_connection_string)
        queues = await sb_mgmt_client.list_queues()
        assert len(queues) == 0
        await sb_mgmt_client.create_queue("test_queue")
        queues = await sb_mgmt_client.list_queues()
        assert len(queues) == 1 and queues[0].queue_name == "test_queue"
        await sb_mgmt_client.delete_queue("test_queue")
        queues = await sb_mgmt_client.list_queues()
        assert len(queues) == 0

        fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net'
        sb_mgmt_client = ServiceBusManagementClient(
            fully_qualified_namespace,
            credential=ServiceBusSharedKeyCredential(
                servicebus_namespace_key_name,
                servicebus_namespace_primary_key))
        queues = await sb_mgmt_client.list_queues()
        assert len(queues) == 0
        await sb_mgmt_client.create_queue("test_queue")
        queues = await sb_mgmt_client.list_queues()
        assert len(queues) == 1 and queues[0].queue_name == "test_queue"
        await sb_mgmt_client.delete_queue("test_queue")
        queues = await sb_mgmt_client.list_queues()
        assert len(queues) == 0
Exemplo n.º 5
0
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
Exemplo n.º 6
0
 async def test_topic_by_sas_token_credential_conn_str_send_basic(
         self, servicebus_namespace, servicebus_namespace_key_name,
         servicebus_namespace_primary_key, servicebus_topic, **kwargs):
     fully_qualified_namespace = servicebus_namespace.name + '.servicebus.windows.net'
     async with ServiceBusClient(
             fully_qualified_namespace=fully_qualified_namespace,
             credential=ServiceBusSharedKeyCredential(
                 policy=servicebus_namespace_key_name,
                 key=servicebus_namespace_primary_key),
             logging_enable=False) as sb_client:
         async with sb_client.get_topic_sender(
                 servicebus_topic.name) as sender:
             message = Message(b"Sample topic message")
             await sender.send_messages(message)
Exemplo n.º 7
0
def example_create_servicebus_client_async():
    # [START create_sb_client_from_conn_str_async]
    import os
    from azure.servicebus.aio import ServiceBusClient
    servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR']
    servicebus_client = ServiceBusClient.from_connection_string(
        conn_str=servicebus_connection_str)
    # [END create_sb_client_from_conn_str_async]

    # [START create_sb_client_async]
    import os
    from azure.servicebus.aio import ServiceBusClient, ServiceBusSharedKeyCredential
    fully_qualified_namespace = os.environ['SERVICE_BUS_CONNECTION_STR']
    shared_access_policy = os.environ['SERVICE_BUS_SAS_POLICY']
    shared_access_key = os.environ['SERVICE_BUS_SAS_KEY']
    servicebus_client = ServiceBusClient(
        fully_qualified_namespace=fully_qualified_namespace,
        credential=ServiceBusSharedKeyCredential(shared_access_policy,
                                                 shared_access_key))
    # [END create_sb_client_async]
    return servicebus_client