Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2a2b28c
[EGv2] Build Release (#30325)
l0lawrence May 19, 2023
0cf20d1
link to samples
l0lawrence May 22, 2023
9f2feda
remove comment
l0lawrence May 22, 2023
626393c
remove uneeded test
l0lawrence May 22, 2023
0d92b59
[EGv2] doc updates (#30483)
l0lawrence May 22, 2023
4487000
[EGv2] Eg typing/formatting (#30492)
l0lawrence May 23, 2023
66cb39d
Beta LiveTests (#30728)
l0lawrence Aug 25, 2023
5ce8776
[EGv2] generate with newer emitter (#31962)
l0lawrence Oct 5, 2023
211d80f
[EGv2] Binary mode (#32922)
l0lawrence Nov 3, 2023
3129eb9
[EventGrid] Ignite Release generate with new typespec (#32652)
l0lawrence Nov 9, 2023
2808655
update for release
l0lawrence Nov 9, 2023
285d5f5
add changelog
l0lawrence Nov 9, 2023
0fff786
[EG] Regenerate beta (#35014)
l0lawrence Mar 29, 2024
9123ac0
[EG] Beta One Client (#34973)
l0lawrence Apr 8, 2024
c1e2e67
[EG] Docstring/update changelog (#35108)
l0lawrence Apr 9, 2024
f1cb640
update readme (#35147)
l0lawrence Apr 10, 2024
49d46d4
beta version
l0lawrence Apr 10, 2024
f48ab90
[EG] Readme updates (#35152)
l0lawrence Apr 11, 2024
47fc92e
type error to value error (#35164)
l0lawrence Apr 11, 2024
2950192
[EG] rename release_delay (#35172)
l0lawrence Apr 11, 2024
7ddd0e5
[EG] regenerate to fix gen code bug (#35327)
l0lawrence Apr 24, 2024
303fc88
ver (#35345)
l0lawrence Apr 24, 2024
ba8a71f
typo (#35348)
l0lawrence Apr 24, 2024
e6b05cb
typo (#35351)
l0lawrence Apr 24, 2024
6186af3
[EG] Archboard Feedback (#35738)
l0lawrence May 30, 2024
7181462
[EG] Update tests (#35833)
l0lawrence May 31, 2024
3b603cf
Merge branch 'main' into feature/eventgrid
l0lawrence May 31, 2024
66bafef
remove print (#35855)
l0lawrence May 31, 2024
6e4a87f
Merge branch 'main' into feature/eventgrid
l0lawrence May 31, 2024
6190bde
[EG] update pyproject and samples (#35857)
l0lawrence Jun 3, 2024
14bfdaf
update readme + version
l0lawrence Jun 3, 2024
bd91117
regen
l0lawrence Jun 3, 2024
6a821f3
Update scripts/devops_tasks/test_run_samples.py
l0lawrence Jun 3, 2024
9a80b90
readme
l0lawrence Jun 3, 2024
88e1a09
typo
l0lawrence Jun 3, 2024
3dd74c3
update
l0lawrence Jun 4, 2024
77abc56
add tests
l0lawrence Jun 4, 2024
1b85d9e
updates tests 2
l0lawrence Jun 4, 2024
1b9ed9b
Revert "updates tests 2"
l0lawrence Jun 4, 2024
06d4bef
try
l0lawrence Jun 4, 2024
e74d7b4
typeError
l0lawrence Jun 4, 2024
a56bf9e
missing await
l0lawrence Jun 4, 2024
1cd9f27
unused import
l0lawrence Jun 5, 2024
4909e83
test rbac (#35953)
l0lawrence Jun 6, 2024
eea5393
readme updates
l0lawrence Jun 7, 2024
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
Prev Previous commit
readme updates
  • Loading branch information
l0lawrence committed Jun 7, 2024
commit eea539336e70cd176780a0e48fe284637ba8d391
88 changes: 30 additions & 58 deletions sdk/eventgrid/azure-eventgrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Azure Event Grid is a fully-managed intelligent event routing service that allows for uniform event consumption using a publish-subscribe model.

| [Source code][python-eg-src]
[Source code][python-eg-src]
| [Package (PyPI)][python-eg-pypi]
| [Package (Conda)](https://anaconda.org/microsoft/azure-eventgrid/)
| [API reference documentation][python-eg-ref-docs]
Expand Down Expand Up @@ -57,14 +57,17 @@ In order to interact with the Event Grid service, you will need to create an ins
An **endpoint** and **credential** are necessary to instantiate the client object.


The default EventGridPublisherClient created is compatible with an Event Grid Basic Resource. To create an Event Grid Namespace compatible Client, specify `namespace_topic="YOUR_TOPIC_NAME"` when instantiating the client.
The default EventGridPublisherClient created is compatible with an Event Grid Basic Resource. To create an Event Grid Namespace compatible client, specify `namespace_topic="YOUR_TOPIC_NAME"` when instantiating the client.

```python
# Event Grid Namespace client
client = EventGridPublisherClient(endpoint, credential, namespace_topic=YOUR_TOPIC_NAME)

# Event Grid Basic Client
client = EventGridPublisherClient(endpoint, credential)
```

EventGridConsumerClient only supports EventGrid Namespaces.
EventGridConsumerClient only supports Event Grid Namespaces.
```python
# Event Grid Namespace Client
client = EventGridConsumerClient(endpoint, credential, namespace_topic=YOUR_TOPIC_NAME, subscription=YOUR_SUBSCRIPTION_NAME)
Expand All @@ -74,9 +77,11 @@ client = EventGridConsumerClient(endpoint, credential, namespace_topic=YOUR_TOPI

Azure Event Grid provides integration with Azure Active Directory (Azure AD) for identity-based authentication of requests. With Azure AD, you can use role-based access control (RBAC) to grant access to your Azure Event Grid resources to users, groups, or applications.

To send events to a topic or domain with a `TokenCredential`, the authenticated identity should have the "EventGrid Data Sender" role assigned.
To receive events to a topic with a `TokenCredential`, the authenticated identity should have the "EventGrid Data Receiver" role assigned.
To send and receive events to/from a topic with a `TokenCredential`, the authenticated identity should have the "EventGrid Data Contributor" role assigned.
To send events to a topic or domain with a `TokenCredential`, the authenticated identity should have the "Event Grid Data Sender" role assigned.
To receive events from a topic event subscription with a `TokenCredential`, the authenticated identity should have the "Event Grid Data Receiver" role assigned.
To send and receive events to/from a topic with a `TokenCredential`, the authenticated identity should have the "Event Grid Data Contributor" role assigned.

More about RBAC setup can be found [here](https://learn.microsoft.com/azure/role-based-access-control/role-assignments-steps).

With the `azure-identity` package, you can seamlessly authorize requests in both development and production environments. To learn more about Azure Active Directory, see the [`azure-identity` README](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/README.md).

Expand Down Expand Up @@ -134,7 +139,7 @@ client = EventGridPublisherClient(endpoint, credential_key)

## Key concepts

### *Event Grid Namespace*
### Event Grid Namespace

A **[namespace](https://learn.microsoft.com/azure/event-grid/concepts-event-grid-namespaces#namespaces)** is a management container for other resources. It allows for grouping of related resources in order to manage them under one subscription.

Expand All @@ -147,10 +152,10 @@ A **[namespace topic](https://learn.microsoft.com/azure/event-grid/concepts-even
An **[event subscription](https://learn.microsoft.com/azure/event-grid/concepts-event-grid-namespaces#event-subscriptions)** is a configuration resource associated with a single topic.


### *Event Grid Basic*
### Event Grid Basic

#### Topic
A **[topic](https://docs.microsoft.com/azure/event-grid/concepts#topics)** is a channel within the EventGrid service to send events. The event schema that a topic accepts is decided at topic creation time. If events of a schema type are sent to a topic that requires a different schema type, errors will be raised.
A **[topic](https://docs.microsoft.com/azure/event-grid/concepts#topics)** is a channel within the Event Grid service to send events. The event schema that a topic accepts is decided at topic creation time. If events of a schema type are sent to a topic that requires a different schema type, errors will be raised.

#### Domain
An event **[domain](https://docs.microsoft.com/azure/event-grid/event-domains)** is a management tool for large numbers of Event Grid topics related to the same application. They allow you to publish events to thousands of topics. Domains also give you authorization and authentication control over each topic. For more information, visit [Event domain overview](https://docs.microsoft.com/azure/event-grid/event-domains).
Expand All @@ -174,15 +179,15 @@ For complete list of recognizable system topics, visit [System Topics](https://d

If you are using Event Grid Basic, regardless of the schema that your topic or domain is configured to use, `EventGridPublisherClient` will be used to publish events to it. Use the `send` method to publish events.

The following formats of events are allowed to be sent to an EventGrid Basic resource:
The following formats of events are allowed to be sent to an Event Grid Basic resource:
- A list or a single instance of strongly typed EventGridEvents.
- A dict representation of a serialized EventGridEvent object.
- A list or a single instance of strongly typed CloudEvents.
- A dict representation of a serialized CloudEvent object.

- A dict representation of any Custom Schema.

The following formats of events are allowed to be sent to an EventGrid Namespace resource, when a namespace topic is specified:
The following formats of events are allowed to be sent to an Event Grid Namespace resource, when a namespace topic is specified:

* A list of single instance of strongly typed CloudEvents.
* A dict representation of a serialized CloudEvent object.
Expand All @@ -209,10 +214,10 @@ This example publishes a Cloud event.
import os
from azure.core.credentials import AzureKeyCredential
from azure.core.messaging import CloudEvent
from azure.eventgrid import EventGridClient
from azure.eventgrid import EventGridPublisherClient

key = os.environ["EVENTGRID_NAMESPACE_KEY"]
endpoint = os.environ["EVENTGRID_NAMESPACE_ENDPOINT"]
key = os.environ["EVENTGRID_KEY"]
endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]


Expand All @@ -223,7 +228,7 @@ event = CloudEvent(
)

credential = AzureKeyCredential(key)
client = EventGridClient(endpoint, credential, namespace_topic=topic_name)
client = EventGridPublisherClient(endpoint, credential, namespace_topic=topic_name)

client.send(event)
```
Expand All @@ -238,10 +243,10 @@ It is possible to send events as a batch when sending multiple events to a topic
import os
from azure.core.credentials import AzureKeyCredential
from azure.core.messaging import CloudEvent
from azure.eventgrid import EventGridClient
from azure.eventgrid import EventGridPublisherClient

key = os.environ["EVENTGRID_NAMESPACE_KEY"]
endpoint = os.environ["EVENTGRID_NAMESPACE_ENDPOINT"]
key = os.environ["EVENTGRID_KEY"]
endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]

event0 = CloudEvent(
Expand All @@ -258,14 +263,14 @@ event1 = CloudEvent(
events = [event0, event1]

credential = AzureKeyCredential(key)
client = EventGridClient(endpoint, credential, namespace_topic=topic_name)
client = EventGridPublisherClient(endpoint, credential, namespace_topic=topic_name)

client.send(events)
```

### Receive and Process Events from Namespace

Use EventGridClient's receive function to receive CloudEvents from a Namespace event subscription. Then try to acknowledge, reject, release or renew the locks.
Use EventGridConsumerClient's receive function to receive CloudEvents from a Namespace event subscription. Then try to acknowledge, reject, release or renew the locks.

```python
import os
Expand Down Expand Up @@ -315,40 +320,13 @@ reject_result = client.reject(

```

### Legacy EventGrid operations
#### Send an Event Grid Event


This example publishes an Event Grid event.

```python
import os
from azure.core.credentials import AzureKeyCredential
from azure.eventgrid import EventGridPublisherClient, EventGridEvent

key = os.environ["EG_ACCESS_KEY"]
endpoint = os.environ["EG_TOPIC_HOSTNAME"]

event = EventGridEvent(
data={"team": "azure-sdk"},
subject="Door1",
event_type="Azure.Sdk.Demo",
data_version="2.0"
)

credential = AzureKeyCredential(key)
client = EventGridPublisherClient(endpoint, credential)

client.send(event)
```

## Distributed Tracing with EventGrid
## Distributed Tracing with Event Grid

You can use OpenTelemetry for Python as usual with EventGrid since it's compatible with azure-core tracing integration.
You can use OpenTelemetry for Python as usual with Event Grid since it's compatible with azure-core tracing integration.

Here is an example of using OpenTelemetry to trace sending a CloudEvent.

First, set OpenTelemetry as enabled tracing plugin for EventGrid.
First, set OpenTelemetry as enabled tracing plugin for Event Grid.

```python
from azure.core.settings import settings
Expand Down Expand Up @@ -423,21 +401,15 @@ The following section provides several code snippets illustrating common pattern

These code samples show common champion scenario operations with the Azure Event Grid client library.

#### Namespaces EventGrid Scenarios

* Authenticate the client: [sample_authentication.py][python-eg-auth]
* Sample of all operations: [sample_all_operations.py][python-eg-client-all-ops-sample]
* Publish cloud event in binary mode: [sample_binary_mode_operation.py][python-eg-client-binary-mode-sample]

#### Basic EventGrid Scenarios
#### Basic Event Grid Scenarios

* Generate Shared Access Signature: [sample_generate_sas.py][python-eg-generate-sas]

* Authenticate the client: [sample_authentication.py][python-eg-auth] ([async_version][python-eg-auth-async])

* Publish events to a topic using SAS: [sample_publish_events_to_a_topic_using_sas_credential_async.py][python-eg-sample-send-using-sas] ([async_version][python-eg-sample-send-using-sas-async])
* Publish Event Grid Events to a topic: [sample_publish_eg_events_to_a_topic.py][python-eg-sample-eg-event] ([async_version][python-eg-sample-eg-event-async])
* Publish EventGrid Events to a domain topic: [sample_publish_eg_events_to_a_domain_topic.py][python-eg-sample-eg-event-to-domain] ([async_version][python-eg-sample-eg-event-to-domain-async])
* Publish Event Grid Events to a domain topic: [sample_publish_eg_events_to_a_domain_topic.py][python-eg-sample-eg-event-to-domain] ([async_version][python-eg-sample-eg-event-to-domain-async])
* Publish a Cloud Event: [sample_publish_events_using_cloud_events_1.0_schema.py][python-eg-sample-send-cloudevent] ([async_version][python-eg-sample-send-cloudevent-async])
* Publish a Custom Schema: [sample_publish_custom_schema_to_a_topic.py][python-eg-publish-custom-schema] ([async_version][python-eg-publish-custom-schema-async])

Expand Down