Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eventhubs track2 preview one #6046

Merged
merged 55 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
599896f
remove async_ops
May 18, 2019
384e802
EventHubs track2 starter (#5330)
YijunXieMS May 21, 2019
24219aa
Eventhubs track2 python main issues (#5575)
YijunXieMS Jun 3, 2019
b77d019
Error hierarchy, sample code and docstring (#5743)
YijunXieMS Jun 14, 2019
87c11dd
Fix missing consumer group directory in EPH
Jun 17, 2019
89bb40e
Fix livetest code problem
Jun 17, 2019
06a6ebf
history and readme
Jun 17, 2019
edeaffd
Update history and setup (#5902)
yunhaoling Jun 17, 2019
106976f
EventPosition.first_available_event -> earliest
Jun 18, 2019
72e420e
Change EventSender's event_position to be mandatory
Jun 18, 2019
f353da8
Update uamqp shared_req to 1.2.0
Jun 18, 2019
4df0aaf
Disable network_tracing
Jun 18, 2019
a8c7a50
update uamqp dependency ~=1.2.0
Jun 18, 2019
daf3d71
Remove EventPosition helper functions
Jun 19, 2019
fc0ce06
Names changed to EventHubConsumer/Producer
Jun 19, 2019
a73bf7b
Avoid nested with statement
Jun 19, 2019
e47ce29
Skip forced reconnect test
Jun 19, 2019
ef3ac56
Update naming in eventhub (consumer and producer). (#5984)
yunhaoling Jun 20, 2019
86af983
Remove azure-core requirement tentatively
Jun 20, 2019
981fc99
Warn when eventhubs or storage teardown fails
Jun 20, 2019
3074c79
add type hints comments
Jun 20, 2019
dbf7001
add azure identity in dev_requirements
Jun 21, 2019
e7ff951
put TransportType in __init__ directly
Jun 21, 2019
9ce3f8e
change EventData's offset to be str, not EventPosition
Jun 21, 2019
95bba82
remove from_iot_connection_string
Jun 21, 2019
b3a6bb4
small fix
Jun 21, 2019
437a6fe
docstring timeout from int to float
Jun 21, 2019
168e522
fix TransportType import
Jun 21, 2019
17c748f
add pytest option sleep for reconnect test
Jun 21, 2019
cb1017f
Fix eventposition issue in receive test
Jun 21, 2019
1288a8b
fix constants import issue
Jun 21, 2019
f03fee1
remove azure identity dev_req
Jun 21, 2019
980b4f0
fix some example issues
Jun 21, 2019
4e2a6e1
iot string fix
Jun 21, 2019
7a5aa4d
Change filename for consumer and producer
Jun 21, 2019
613a6c4
Vendor azure-storage-blob in eventprocesshost (#6018)
yunhaoling Jun 21, 2019
002a50f
Add vendored blob-storage required pkg
Jun 22, 2019
cb5f979
Vendor storage 2.0.1 within EPH (#6031)
yunhaoling Jun 22, 2019
f6dcf2d
catch exception for mgmt_request
Jun 23, 2019
c6ae04a
Update comment and code structure (#6042)
yunhaoling Jun 23, 2019
ce8b0c9
code review changes
Jun 24, 2019
3f808f9
Merge branch 'master' into eventhubs_dev
Jun 24, 2019
8786b9a
Add python-dateutil in shared_requirements
Jun 24, 2019
041e36b
Add aad credential env var to tests.yml
Jun 24, 2019
9a4c14c
Change example code assertion for parallel running
Jun 24, 2019
5abdcd7
Enable iothub receive test case
Jun 24, 2019
c0990d2
Revert "Enable iothub receive test case"
Jun 24, 2019
65bfec5
fix auth test error
Jun 24, 2019
6d017e1
change offset.value to offset
Jun 24, 2019
94c2eec
Fix an eventposition problem
Jun 24, 2019
59e57b7
Remove path append
Jun 24, 2019
fe6459b
trying removing the module init py within tests
scbedd Jun 24, 2019
cbbbfc4
Separate MockEventProcessor to a different file
Jun 24, 2019
4b44f0c
remove tests to path
Jun 24, 2019
41ae796
trying a run based on a nested conftest to establish the async fixtur…
scbedd Jun 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,49 +1,63 @@
.. :changelog:

Release History
===============

1.3.1 (2019-02-28)
------------------
# Release History

## 2.0.0b1 (2019-06-25)

- Added more configuration parameters when creating EventHubClient.
- New error hierarchy
- `azure.error.EventHubError`
- `azure.error.ConnectionLostError`
- `azure.error.ConnectError`
- `azure.error.AuthenticationError`
- `azure.error.EventDataError`
- `azure.error.EventDataSendError`
- Renamed Sender/Receiver to EventHubProducer/EventHubConsumer
- New APIs for creating EventHubProducer/EventHubConsumer.
- EventHubConsumer is now iterable.
- Rename class azure.eventhub.Offset to azure.eventhub.EventPosition
- Reorganized connection management, EventHubClient is no longer responsible for opening/closing EventHubProducer/EventHubConsumer.
- Each EventHubProducer/EventHubConsumer is responsible for its own connection management.
- Added support for context manager on EventHubProducer and EventHubConsumer.
- Reorganized async APIs into "azure.eventhub.aio" namespace and rename to drop the "_async" suffix.
- Added support for authentication using azure-core credential.
- Added support for transport using AMQP over WebSocket.
- Updated uAMQP dependency to 1.2.0


## 1.3.1 (2019-02-28)

**BugFixes**

- Fixed bug where datetime offset filter was using a local timestamp rather than UTC.
- Fixed stackoverflow error in continuous connection reconnect attempts.


1.3.0 (2019-01-29)
------------------
## 1.3.0 (2019-01-29)

**Bugfixes**
**BugFixes**

- Added support for auto reconnect on token expiration and other auth errors (issue #89).

**Features**

- Added ability to create ServiceBusClient from an existing SAS auth token, including
provding a function to auto-renew that token on expiry.
providing a function to auto-renew that token on expiry.
- Added support for storing a custom EPH context value in checkpoint (PR #84, thanks @konstantinmiller)


1.2.0 (2018-11-29)
------------------
## 1.2.0 (2018-11-29)

- Support for Python 2.7 in azure.eventhub module (azure.eventprocessorhost will not support Python 2.7).
- Parse EventData.enqueued_time as a UTC timestamp (issue #72, thanks @vjrantal)


1.1.1 (2018-10-03)
------------------
## 1.1.1 (2018-10-03)

- Fixed bug in Azure namespace package.


1.1.0 (2018-09-21)
------------------
## 1.1.0 (2018-09-21)

- Changes to `AzureStorageCheckpointLeaseManager` parameters to support other connection options (issue #61):

- The `storage_account_name`, `storage_account_key` and `lease_container_name` arguments are now optional keyword arguments.
- Added a `sas_token` argument that must be specified with `storage_account_name` in place of `storage_account_key`.
- Added an `endpoint_suffix` argument to support storage endpoints in National Clouds.
Expand All @@ -54,8 +68,7 @@ Release History
- Added convenience methods `body_as_str` and `body_as_json` to EventData object for easier processing of message data.


1.0.0 (2018-08-22)
------------------
## 1.0.0 (2018-08-22)

- API stable.
- Renamed internal `_async` module to `async_ops` for docs generation.
Expand All @@ -66,8 +79,7 @@ Release History
- Reformatted logging for performance.


0.2.0 (2018-08-06)
------------------
## 0.2.0 (2018-08-06)

- Stability improvements for EPH.
- Updated uAMQP version.
Expand All @@ -82,8 +94,7 @@ Release History
- `EPHOptions.auto_reconnect_on_error`


0.2.0rc2 (2018-07-29)
---------------------
## 0.2.0rc2 (2018-07-29)

- **Breaking change** `EventData.offset` will now return an object of type `~uamqp.common.Offset` rather than str.
The original string value can be retrieved from `~uamqp.common.Offset.value`.
Expand All @@ -95,8 +106,7 @@ Release History
- Added keep-alive thread for maintaining an unused connection.


0.2.0rc1 (2018-07-06)
---------------------
## 0.2.0rc1 (2018-07-06)

- **Breaking change** Restructured library to support Python 3.7. Submodule `async` has been renamed and all classes from
this module can now be imported from azure.eventhub directly.
Expand All @@ -110,29 +120,25 @@ Release History
- Dropped Python 2.7 wheel support.


0.2.0b2 (2018-05-29)
--------------------
## 0.2.0b2 (2018-05-29)

- Added `namespace_suffix` to EventHubConfig() to support national clouds.
- Added `device_id` attribute to EventData to support IoT Hub use cases.
- Added message header to workaround service bug for PartitionKey support.
- Updated uAMQP dependency to vRC1.


0.2.0b1 (2018-04-20)
--------------------
## 0.2.0b1 (2018-04-20)

- Updated uAMQP to latest version.
- Further testing and minor bug fixes.


0.2.0a2 (2018-04-02)
--------------------
## 0.2.0a2 (2018-04-02)

- Updated uAQMP dependency.


0.2.0a1 (unreleased)
--------------------
## 0.2.0a1 (unreleased)

- Swapped out Proton dependency for uAMQP.
241 changes: 241 additions & 0 deletions sdk/eventhub/azure-eventhubs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# Azure Event Hubs client library for Python

Azure Event Hubs is a big data streaming platform and event ingestion service. It can receive and process millions of events per second.

Use the Event Hubs client library for Python to:

- Publish events to the Event Hubs service through a producer.
- Read events from the Event Hubs service through a consumer.

On Python 3.5.3 and above, it also includes:

- An async producer and consumer that supports async/await methods.
- An Event Processor Host module that manages the distribution of partition readers.

[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhubs) | [Package (PyPi)](https://pypi.org/project/azure-eventhub/) | [API reference documentation](https://docs.microsoft.com/python/api/azure-eventhub) | [Product documentation](https://docs.microsoft.com/en-ca/azure/event-hubs/)

# Getting started

## Install the package

Install the Azure Event Hubs client library for Python with pip:

```
$ pip install azure-eventhub
```

### Prerequisites

- An Azure subscription.
- Python 2.7, 3.5 or later.
- An existing Event Hubs namespace and event hub. You can create these entities by following the instructions in [this article](https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-create)

## Authenticate the client

Interaction with Event Hubs starts with an instance of the EventHubClient class. You need the host name, SAS/AAD credential and event hub name to instantiate the client object.

### Get credentials

You can find credential information in [Azure Portal](https://portal.azure.com/).

### Create client

There are several ways to instantiate the EventHubClient object and the following code snippets demonstrate one way:

```python
import os
from azure.eventhub import EventHubClient

connection_str = "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format(
os.environ['EVENT_HUB_HOSTNAME'],
os.environ['EVENT_HUB_SAS_POLICY'],
os.environ['EVENT_HUB_SAS_KEY'],
os.environ['EVENT_HUB_NAME'])
client = EventHubClient.from_connection_string(connection_str)
```

# Key concepts

- **Namespace:** An Event Hubs namespace provides a unique scoping container, referenced by its fully qualified domain name, in which you create one or more event hubs or Kafka topics.

- **Event publishers**: Any entity that sends data to an event hub is an event producer, or event publisher. Event publishers can publish events using HTTPS or AMQP 1.0 or Kafka 1.0 and later. Event publishers use a Shared Access Signature (SAS) token to identify themselves to an event hub, and can have a unique identity, or use a common SAS token.

- **Event consumers**: Any entity that reads event data from an event hub is an event consumer. All Event Hubs consumers connect via the AMQP 1.0 session and events are delivered through the session as they become available. The client does not need to poll for data availability.

- **SAS tokens**: Event Hubs uses Shared Access Signatures, which are available at the namespace and event hub level. A SAS token is generated from a SAS key and is an SHA hash of a URL, encoded in a specific format. Using the name of the key (policy) and the token, Event Hubs can regenerate the hash and thus authenticate the sender.

For more information about these concepts, see [Features and terminology in Azure Event Hubs](https://docs.microsoft.com/en-ca/azure/event-hubs/event-hubs-features).

# Examples

The following sections provide several code snippets covering some of the most common Event Hubs tasks, including:

- [Send event data](#send-event-data)
- [Receive event data](#receive-event-data)
- [Async send event data](#async-send-event-data)
- [Async receive event data](#async-receive-event-data)

## Send event data

Sends an event data and blocks until acknowledgement is received or operation times out.

```python
import os
from azure.eventhub import EventHubClient, EventData

connection_str = "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format(
os.environ['EVENT_HUB_HOSTNAME'],
os.environ['EVENT_HUB_SAS_POLICY'],
os.environ['EVENT_HUB_SAS_KEY'],
os.environ['EVENT_HUB_NAME'])
client = EventHubClient.from_connection_string(connection_str)
sender = client.create_producer(partition_id="0")

try:
event_list = []
for i in range(10):
event_list.append(EventData(b"A single event"))

with sender:
sender.send(event_list)
except:
raise
finally:
pass
```

## Receive event data

Receive events from the EventHub.

```python
import os
import logging
from azure.eventhub import EventHubClient, EventData, EventPosition

connection_str = "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format(
os.environ['EVENT_HUB_HOSTNAME'],
os.environ['EVENT_HUB_SAS_POLICY'],
os.environ['EVENT_HUB_SAS_KEY'],
os.environ['EVENT_HUB_NAME'])
client = EventHubClient.from_connection_string(connection_str)
receiver = client.create_consumer(consumer_group="$default", partition_id="0", event_position=EventPosition.new_events_only())

try:
logger = logging.getLogger("azure.eventhub")
with receiver:
received = receiver.receive(max_batch_size=100, timeout=5)
for event_data in received:
logger.info("Message received:{}".format(event_data.body_as_str()))
except:
raise
finally:
pass
```

## Async send event data

Sends an event data and asynchronously.

```python
import os
from azure.eventhub.aio import EventHubClient
from azure.eventhub import EventData

connection_str = "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format(
os.environ['EVENT_HUB_HOSTNAME'],
os.environ['EVENT_HUB_SAS_POLICY'],
os.environ['EVENT_HUB_SAS_KEY'],
os.environ['EVENT_HUB_NAME'])
client = EventHubClient.from_connection_string(connection_str)
sender = client.create_producer(partition_id="0")

try:
event_list = []
for i in range(10):
event_list.append(EventData(b"A single event"))

async with sender:
await sender.send(event_list)
except:
raise
finally:
pass
```

## Async receive event data

Receive events asynchronously from the EventHub.

```python
import os
import logging
from azure.eventhub.aio import EventHubClient
from azure.eventhub import EventData, EventPosition

connection_str = "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format(
os.environ['EVENT_HUB_HOSTNAME'],
os.environ['EVENT_HUB_SAS_POLICY'],
os.environ['EVENT_HUB_SAS_KEY'],
os.environ['EVENT_HUB_NAME'])
client = EventHubClient.from_connection_string(connection_str)
receiver = client.create_consumer(consumer_group="$default", partition_id="0", event_position=EventPosition.new_events_only())

try:
logger = logging.getLogger("azure.eventhub")
async with receiver:
received = await receiver.receive(max_batch_size=100, timeout=5)
for event_data in received:
logger.info("Message received:{}".format(event_data.body_as_str()))
except:
raise
finally:
pass
```

# Troubleshooting

## General

The Event Hubs APIs generate the following exceptions.

- **AuthenticationError:** Failed to authenticate because of wrong address, SAS policy/key pair, SAS token or azure identity.
- **ConnectError:** Failed to connect to the EventHubs. The AuthenticationError is a type of ConnectError.
- **ConnectionLostError:** Lose connection after a connection has been built.
- **EventDataError:** The EventData to be sent fails data validation.
For instance, this error is raised if you try to send an EventData that is already sent.
- **EventDataSendError:** The Eventhubs service responds with an error when an EventData is sent.
- **EventHubError:** All other Eventhubs related errors. It is also the root error class of all the above mentioned errors.

# Next steps

## Examples

- ./examples/send.py - use sender to publish events
- ./examples/recv.py - use receiver to read events
- ./examples/send_async.py - async/await support of a sender
- ./examples/recv_async.py - async/await support of a receiver
- ./examples/eph.py - event processor host

## Documentation

Reference documentation is available at https://docs.microsoft.com/python/api/azure-eventhub.

## Logging

- Enable 'azure.eventhub' logger to collect traces from the library.
- Enable 'uamqp' logger to collect traces from the underlying uAMQP library.
- Enable AMQP frame level trace by setting `network_tracing=True` when creating the client.

## Provide Feedback

If you encounter any bugs or have suggestions, please file an issue in the [Issues](https://github.com/Azure/azure-sdk-for-python/issues) section of the project.

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
Loading