Esempio n. 1
0
def test_get_properties_with_auth_error_sync(live_eventhub):
    client = EventHubConsumerClient(
        live_eventhub['hostname'], live_eventhub['event_hub'], '$default',
        EventHubSharedKeyCredential(live_eventhub['key_name'],
                                    "AaBbCcDdEeFf="))
    with client:
        with pytest.raises(AuthenticationError) as e:
            client.get_eventhub_properties()

    client = EventHubConsumerClient(
        live_eventhub['hostname'], live_eventhub['event_hub'], '$default',
        EventHubSharedKeyCredential("invalid", live_eventhub['access_key']))
    with client:
        with pytest.raises(AuthenticationError) as e:
            client.get_eventhub_properties()
Esempio n. 2
0
def test_get_properties(live_eventhub):
    client = EventHubConsumerClient(
        live_eventhub['hostname'], live_eventhub['event_hub'], '$default',
        EventHubSharedKeyCredential(live_eventhub['key_name'],
                                    live_eventhub['access_key']))
    with client:
        properties = client.get_eventhub_properties()
        assert properties['eventhub_name'] == live_eventhub[
            'event_hub'] and properties['partition_ids'] == ['0', '1']
Esempio n. 3
0
def test_get_properties_with_connect_error(live_eventhub):
    client = EventHubConsumerClient(
        live_eventhub['hostname'], "invalid", '$default',
        EventHubSharedKeyCredential(live_eventhub['key_name'],
                                    live_eventhub['access_key']))
    with client:
        with pytest.raises(ConnectError) as e:
            client.get_eventhub_properties()

    client = EventHubConsumerClient(
        "invalid.servicebus.windows.net", live_eventhub['event_hub'],
        '$default',
        EventHubSharedKeyCredential(live_eventhub['key_name'],
                                    live_eventhub['access_key']))
    with client:
        with pytest.raises(
                EventHubError
        ) as e:  # This can be either ConnectError or ConnectionLostError
            client.get_eventhub_properties()
Esempio n. 4
0
def test_client_azure_named_key_credential(live_eventhub):
    credential = AzureNamedKeyCredential(live_eventhub['key_name'],
                                         live_eventhub['access_key'])
    consumer_client = EventHubConsumerClient(
        fully_qualified_namespace=live_eventhub['hostname'],
        eventhub_name=live_eventhub['event_hub'],
        consumer_group='$default',
        credential=credential,
        user_agent='customized information')

    assert consumer_client.get_eventhub_properties() is not None

    credential.update("foo", "bar")

    with pytest.raises(Exception):
        consumer_client.get_eventhub_properties()

    credential.update(live_eventhub['key_name'], live_eventhub['access_key'])
    assert consumer_client.get_eventhub_properties() is not None
Esempio n. 5
0
def create_consumer_client():
    print('Examples showing how to create consumer client.')

    # Create consumer client from connection string.

    consumer_client = EventHubConsumerClient.from_connection_string(
        conn_str=CONNECTION_STRING,  # connection string contains EventHub name.
        consumer_group=CONSUMER_GROUP
    )

    # Illustration of commonly used parameters.
    consumer_client = EventHubConsumerClient.from_connection_string(
        conn_str=CONNECTION_STRING,
        consumer_group=CONSUMER_GROUP,
        eventhub_name=EVENTHUB_NAME,  # EventHub name should be specified if it doesn't show up in connection string.
        logging_enable=False,  # To enable network tracing log, set logging_enable to True.
        retry_total=3,  # Retry up to 3 times to re-do failed operations.
        transport_type=TransportType.Amqp  # Use Amqp as the underlying transport protocol.
    )

    # Create consumer client from constructor.

    consumer_client = EventHubConsumerClient(
        fully_qualified_namespace=FULLY_QUALIFIED_NAMESPACE,
        eventhub_name=EVENTHUB_NAME,
        consumer_group=CONSUMER_GROUP,
        credential=EventHubSharedKeyCredential(
            policy=SAS_POLICY,
            key=SAS_KEY
        ),
        logging_enable=False,  # To enable network tracing log, set logging_enable to True.
        retry_total=3,  # Retry up to 3 times to re-do failed operations.
        transport_type=TransportType.Amqp  # Use Amqp as the underlying transport protocol.
    )

    print("Calling consumer client get eventhub properties:", consumer_client.get_eventhub_properties())