page_type | languages | products | description | urlFragment | ||
---|---|---|---|---|---|---|
sample |
|
|
This contains Python samples for publishing events to Azure Event Grid and consuming events from Azure Event Grid. |
event-grid-python-public-consume-events |
DISCLAIMER: The data plane samples in this repo are for azure-eventgrid v1 (1.x). For the samples for v4 (4.x and above) please visit here. This repo is archived since v4 has become stable. For management plane samples, please visit here.
DISCLAIMER: If you are looking to migrate from azure-eventgrid v1(1.x) to v4(4.x), we suggest getting started at the migration guide.
This contains Python samples for publishing events to Azure Event Grid and consuming events from Azure Event Grid. It also contains a set of management samples that demonstrates how to manage topics and event subscriptions.
These samples demonstrates the following features:
Data Plane:
- How to publish events to Azure Event Grid.
- How to consume events delivered by Azure Event Grid.
The above two samples use the Event Grid data plane SDK azure-eventgrid.
Management Plane:
- How to create a topic and an event subscription to a topic.
- How to create an event subscription to a Storage account.
- How to create an event subscription to an Azure subscription / Resource Group.
The above three samples use the Event Grid management plane SDK azure-mgmt-eventgrid
- Python 2.7, 3.4 or higher.
- Pipenv. If you don't have it, follow the pipenv installation tutorial.
- git clone https://github.com/Azure-Samples/event-grid-python-public-consume-events.git
- cd event-grid-python-public-consume-events
- pipenv install
- For Management only, rename the file
env_template
to.env
and update the correct values inside with your subscription ID and Azure Service Principal credentials.
-
create_eg_topics_and_event_subscriptions.py
creates a new event subscription for an Event Grid Topic, and send it to a webhookIn order for this sample to work, you need to have a valid
.env
file (see previous section).This sample requires a endpoint that supports EventGrid security validation. See https://aka.ms/esvalidation for details
Run the sample :
pipenv run python create_eg_topics_and_event_subscriptions.py
-
create_storage_event_subscriptions.py
creates a new event subscription for a storage account, filtering jpg creation, and send it to an Relay Hybrid ConnectionIn order for this sample to work, you need to have a valid
.env
file (see previous section).Run the sample :
pipenv run python create_storage_event_subscriptions.py
-
create_arm_event_subscriptions.py
creates a new event subscription for an Azure Subscription and send it to a Storage QueueIn order for this sample to work, you need to have a valid
.env
file (see previous section).Run the sample :
pipenv run python create_arm_event_subscriptions.py
-
event_grid_publisher.py
publishes a custom event to a Topic. Topic might be created by the initial samplecreate_eg_topics_and_event_subscriptions.py
or CLI.In order for this sample to work, you need an Event Grid Topic and a Key (replace global variables in the script)
Run the sample :
pipenv run python event_grid_publisher.py
-
ConsumerFunction
is an Azure Function app that receive an event from EventGrid. You can deploy theConsumerFunction
folder to an Azure Function using VSCode, this folder is ready to deploy. See the Readme in that directory for details.If you just want the code, look at
ConsumerFunction/ConsumerFunction/run.py
.Creating an Azure Function is out of the scope of this sample, you can follow CLI tutorial or Portal tutorial or using VSCode.