Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
updates
  • Loading branch information
l0lawrence committed May 22, 2024
commit 7eea6faf0cdfe08d70ea05c356f03d9bf2f1b622
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def receive(
max_wait_time=max_wait_time,
**kwargs,
)
for detail_item in received_result.value:
for detail_item in received_result.details:
deserialized_cloud_event = CloudEvent.from_dict(detail_item.event)
detail_item.event = deserialized_cloud_event
detail_items.append(
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
super().__init__(
endpoint=endpoint,
credential=credential,
api_version=api_version,
api_version=api_version or DEFAULT_STANDARD_API_VERSION,
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async def receive(
max_wait_time=max_wait_time,
**kwargs,
)
for detail_item in receive_result.value:
for detail_item in receive_result.details:
deserialized_cloud_event = CloudEvent.from_dict(detail_item.event)
detail_item.event = deserialized_cloud_event
detail_items.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from azure.eventgrid.aio import EventGridPublisherClient
from azure.core.credentials import AzureKeyCredential

# To Event Grid Basic
topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"]
endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"]

Expand All @@ -44,5 +45,28 @@ async def publish():
])
# [END publish_cloud_event_dict_async]

# To Event Grid Namespaces
topic_endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_key = os.environ["EVENTGRID_KEY"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]
sub = os.environ["EVENTGRID_EVENT_SUBSCRIPTION_NAME"]

credential = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name)

async with client:
await client.send([
{
"type": "Contoso.Items.ItemReceived",
"source": "/contoso/items",
"data": {
"itemSku": "Contoso Item SKU #1"
},
"subject": "Door1",
"specversion": "1.0",
"id": "randomclouduuid11"
}
])

if __name__ == '__main__':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need to run black maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm will double check generating should run black

asyncio.run(publish())
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from azure.core.credentials import AzureKeyCredential
from cloudevents.http import CloudEvent

# To Event Grid Basic
topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"]
endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"]

Expand All @@ -39,5 +40,26 @@ async def publish():
)
])

# To Event Grid Namespaces

topic_endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_key = os.environ["EVENTGRID_KEY"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]

credential = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name)

async with client:
await client.send([
CloudEvent(
attributes={
"type": "cloudevent",
"source": "/cncf/cloud/event/1.0",
"subject": "testing-cncf-event"
},
data=b'This is a cncf cloud event.',
)
])

if __name__ == '__main__':
asyncio.run(publish())
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"https://<YOUR-TOPIC-NAME>.<REGION-NAME>.eventgrid.azure.net/api/events".
"""
import os
from azure.eventgrid import EventGridPublisherClient
from azure.eventgrid import EventGridPublisherClient, EventGridConsumerClient
from azure.core.credentials import AzureKeyCredential


# To Event Grid Basic
topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"]
endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"]

Expand All @@ -39,3 +41,25 @@
}
])
# [END publish_cloud_event_dict]

# To Event Grid Namespaces
topic_endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_key = os.environ["EVENTGRID_KEY"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]
sub = os.environ["EVENTGRID_EVENT_SUBSCRIPTION_NAME"]

credential = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name)

client.send([
{
"type": "Contoso.Items.ItemReceived",
"source": "/contoso/items",
"data": {
"itemSku": "Contoso Item SKU #1"
},
"subject": "Door1",
"specversion": "1.0",
"id": "randomclouduuid11"
}
])
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from azure.core.credentials import AzureKeyCredential
from cloudevents.http import CloudEvent

# To EventGrid Basic
topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"]
endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"]

Expand All @@ -35,3 +36,22 @@
data=b'This is a cncf cloud event.',
)
])

# To Event Grid Namespaces
topic_endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_key = os.environ["EVENTGRID_KEY"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]

credential = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name)

client.send([
CloudEvent(
attributes={
"type": "cloudevent",
"source": "/cncf/cloud/event/1.0",
"subject": "testing-cncf-event"
},
data=b'This is a cncf cloud event.',
)
])