Skip to content

Commit

Permalink
[EventHubs] Improvement on doc and sample (#17833)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhaoling authored Apr 6, 2021
1 parent b20bcbf commit e95f3a2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion sdk/eventhub/azure-eventhub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This version follows from version 5.3.1, rather than 5.4.0b1 so that the preview

**New Features**

- Added support for using `~azure.core.credentials.AzureSasCredential` as credential for authenticating producer and consumer clients.
- Added support for using `azure.core.credentials.AzureSasCredential` as credential for authenticating producer and consumer clients.
- Updated `list_ownership`, `claim_ownership`, `update_checkpoint`, `list_checkpoints` on sync and async `CheckpointStore` to support taking `**kwargs`.
- WARNING: Implementing a custom checkpointstore that does not support taking `**kwargs` in the methods listed previously will result in the following pylint error: `W0221: Parameters differ from overridden ________ method (arguments-differ)`.
- Updated `update_checkpoint` on sync and async `PartitionContext` to support taking `**kwargs`.
Expand Down
7 changes: 5 additions & 2 deletions sdk/eventhub/azure-eventhub/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ Both [sync version](https://github.com/Azure/azure-sdk-for-python/tree/master/sd
- [iot_hub_connection_string_receive_async.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py) - Examples to receive events from an IoT Hub:
- Convert an IoT Hub connection string to the built-in Event Hub endpoint and receive events from it

- [authenticate_with_sas_token.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/sync_samples/authenticate_with_sas_token.py)
- [authenticate_with_sas_token.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/sync_samples/authenticate_with_sas_token.py) ([async_version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/async_samples/authenticate_with_sas_token_async.py)) - Examples:
- Utilize a SAS token to authenticate when creating an Event Hub client.

- [connection_to_custom_endpoint_address.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventhub/azure-eventhub/samples/sync_samples/connection_to_custom_endpoint_address.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventhub/azure-eventhub/samples/async_samples/connection_to_custom_endpoint_address_async.py)) - Examples
- [authenticate_with_azure_sas_credential.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/sync_samples/authenticate_with_azure_sas_credential.py) ([async_version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/async_samples/authenticate_with_azure_sas_credential_async.py)) - Examples:
- Utilize `azure.core.credentials.AzureSasCredential` to authenticate when creating an Event Hub client.

- [connection_to_custom_endpoint_address.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventhub/azure-eventhub/samples/sync_samples/connection_to_custom_endpoint_address.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventhub/azure-eventhub/samples/async_samples/connection_to_custom_endpoint_address_async.py)) - Examples:
to create EventHubProducerClient and EventHubConsumerClient that connect to a custom endpoint with a custom certificate.

## Prerequisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# --------------------------------------------------------------------------------------------

"""
Example to demonstrate utilizing azure.core.credentials.AzureSasCredential to authenticate with EventHub
Example to demonstrate utilizing azure.core.credentials.AzureSasCredential to authenticate with Event Hubs.
"""

# pylint: disable=C0111
Expand All @@ -22,7 +22,7 @@
except ImportError:
from urllib import pathname2url as url_parse_quote

from azure.core.credentials import AccessToken, AzureSasCredential
from azure.core.credentials import AzureSasCredential
from azure.eventhub.aio import EventHubProducerClient
from azure.eventhub import EventData

Expand All @@ -39,12 +39,12 @@ def generate_sas_token(uri, sas_name, sas_value, token_ttl):
# Target namespace and hub must also be specified. Consumer group is set to default unless required otherwise.
FULLY_QUALIFIED_NAMESPACE = os.environ['EVENT_HUB_HOSTNAME']
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME']
CONSUMER_GROUP = "$Default"

# The following part creates a SAS token. A SAS token is typically given to you after being created.
SAS_POLICY = os.environ['EVENT_HUB_SAS_POLICY']
SAS_KEY = os.environ['EVENT_HUB_SAS_KEY']


async def create_with_sas_token():
uri = "sb://{}/{}".format(FULLY_QUALIFIED_NAMESPACE, EVENTHUB_NAME)
token_ttl = 3000 # seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# --------------------------------------------------------------------------------------------

"""
Example to demonstrate utilizing SAS (Shared Access Signature) tokens to authenticate with ServiceBus
Example to demonstrate utilizing SAS (Shared Access Signature) tokens to authenticate with Event Hubs
"""

# pylint: disable=C0111
Expand Down Expand Up @@ -58,12 +58,12 @@ async def get_token(self, *scopes, **kwargs):
# Target namespace and hub must also be specified. Consumer group is set to default unless required otherwise.
FULLY_QUALIFIED_NAMESPACE = os.environ['EVENT_HUB_HOSTNAME']
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME']
CONSUMER_GROUP = "$Default"

# The following part creates a SAS token. Users can use any way to create a SAS token.
SAS_POLICY = os.environ['EVENT_HUB_SAS_POLICY']
SAS_KEY = os.environ['EVENT_HUB_SAS_KEY']


async def create_with_sas_token():
uri = "sb://{}/{}".format(FULLY_QUALIFIED_NAMESPACE, EVENTHUB_NAME)
token_ttl = 3000 # seconds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
azure-eventhub-checkpointstoreblob
azure-eventhub-checkpointstoreblob-aio; python_version >= '3.5'
azure-eventhub-checkpointstoreblob-aio; python_version >= '3.6'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# --------------------------------------------------------------------------------------------

"""
Example to demonstrate utilizing azure.core.credentials.AzureSasCredential to authenticate with EventHub
Example to demonstrate utilizing azure.core.credentials.AzureSasCredential to authenticate with Event Hubs.
"""

# pylint: disable=C0111
Expand Down Expand Up @@ -34,13 +34,10 @@ def generate_sas_token(uri, sas_name, sas_value, token_ttl):
signature = url_parse_quote(base64.b64encode(signed_hmac_sha256.digest()))
return 'SharedAccessSignature sr={}&sig={}&se={}&skn={}'.format(uri, signature, expiry, sas_name)

def on_event(context, event):
print(context.partition_id, ":", event)

# Target namespace and hub must also be specified. Consumer group is set to default unless required otherwise.
FULLY_QUALIFIED_NAMESPACE = os.environ['EVENT_HUB_HOSTNAME']
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME']
CONSUMER_GROUP = "$Default"

# The following part creates a SAS token. A SAS token is typically given to you after being created.
SAS_POLICY = os.environ['EVENT_HUB_SAS_POLICY']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# --------------------------------------------------------------------------------------------

"""
Example to demonstrate utilizing SAS (Shared Access Signature) tokens to authenticate with EventHub
Example to demonstrate utilizing SAS (Shared Access Signature) tokens to authenticate with Event Hubs.
"""

# pylint: disable=C0111
Expand Down Expand Up @@ -34,9 +34,6 @@ def generate_sas_token(uri, sas_name, sas_value, token_ttl):
signature = url_parse_quote(base64.b64encode(signed_hmac_sha256.digest()))
return 'SharedAccessSignature sr={}&sig={}&se={}&skn={}'.format(uri, signature, expiry, sas_name)

def on_event(context, event):
print(context.partition_id, ":", event)


class CustomizedSASCredential(object):
def __init__(self, token, expiry):
Expand All @@ -59,7 +56,6 @@ def get_token(self, *scopes, **kwargs):
# Target namespace and hub must also be specified. Consumer group is set to default unless required otherwise.
FULLY_QUALIFIED_NAMESPACE = os.environ['EVENT_HUB_HOSTNAME']
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME']
CONSUMER_GROUP = "$Default"

# The following part creates a SAS token. Users can use any way to create a SAS token.
SAS_POLICY = os.environ['EVENT_HUB_SAS_POLICY']
Expand Down

0 comments on commit e95f3a2

Please sign in to comment.