Skip to content

Commit 609c33c

Browse files
author
Jill Grant
authored
Merge pull request #287264 from spelluru/egridcloudevents0924-2
Cloud Event Schema
2 parents a2325d9 + a2ab36e commit 609c33c

File tree

6 files changed

+141
-215
lines changed

6 files changed

+141
-215
lines changed

articles/event-grid/.openpublishing.redirection.event-grid.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"redirections": [
3+
{
4+
"source_path": "cloudevents-schema.md",
5+
"redirect_url": "/azure/event-grid/cloud-event-schema",
6+
"redirect_document_id": false
7+
},
38
{
49
"source_path": "storage-upload-process-images.md",
510
"redirect_url": "/azure/event-grid/blob-event-quickstart-portal",

articles/event-grid/cloud-event-schema.md

Lines changed: 133 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
---
22
title: CloudEvents v1.0 schema with Azure Event Grid
33
description: Describes how to use the CloudEvents v1.0 schema for events in Azure Event Grid. The service supports events in the JSON implementation of Cloud Events.
4-
ms.topic: conceptual
5-
ms.date: 05/24/2023
4+
ms.topic: how-to
5+
ms.date: 09/24/2024
6+
#customer intent: As a developer, I want to know how to use Cloud Events schema with Azure Event Grid.
67
---
78

89
# CloudEvents v1.0 schema with Azure Event Grid
910

10-
Azure Event Grid natively supports events in the [JSON implementation of CloudEvents v1.0](https://github.com/cloudevents/spec/blob/v1.0/json-format.md) and [HTTP protocol binding](https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md). [CloudEvents](https://cloudevents.io/) is an [open specification](https://github.com/cloudevents/spec/blob/v1.0/spec.md) for describing event data.
11-
12-
CloudEvents simplifies interoperability by providing a common event schema for publishing, and consuming cloud based events. This schema allows for uniform tooling, standard ways of routing & handling events, and universal ways of deserializing the outer event schema. With a common schema, you can more easily integrate work across platforms.
11+
Azure Event Grid natively supports events in the [JSON implementation of CloudEvents v1.0](https://github.com/cloudevents/spec/blob/v1.0/json-format.md) and [HTTP protocol binding](https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md). [CloudEvents](https://cloudevents.io/) is an [open specification](https://github.com/cloudevents/spec/blob/v1.0/spec.md) for describing event data. CloudEvents simplifies interoperability by providing a common event schema for publishing, and consuming cloud based events. This schema allows for uniform tooling, standard ways of routing & handling events, and universal ways of deserializing the outer event schema. With a common schema, you can more easily integrate work across platforms.
1312

1413
CloudEvents is being built by several [collaborators](https://github.com/cloudevents/spec/blob/main/docs/contributors.md), including Microsoft, through the [Cloud Native Computing Foundation](https://www.cncf.io/). It's currently available as version 1.0.
1514

16-
This article describes CloudEvents schema with Event Grid.
15+
This article describes using CloudEvents schema with Event Grid.
1716

1817
## Sample event using CloudEvents schema
1918

@@ -48,7 +47,7 @@ A detailed description of the available fields, their types, and definitions in
4847

4948
The headers values for events delivered in the CloudEvents schema and the Event Grid schema are the same except for `content-type`. For CloudEvents schema, that header value is `"content-type":"application/cloudevents+json; charset=utf-8"`. For Event Grid schema, that header value is `"content-type":"application/json; charset=utf-8"`.
5049

51-
## Event Grid for CloudEvents
50+
## Configuration for CloudEvents
5251

5352
You can use Event Grid for both input and output of events in CloudEvents schema. You can use CloudEvents for system events, like Blob Storage events and IoT Hub events, and custom events. In addition to supporting CloudEvents, Event Grid supports a proprietary, nonextensible, yet fully functional [Event Grid event format](event-schema.md). The following table describes the transformation supported when using CloudEvents and Event Grid formats as an input schema in topics and as an output schema in event subscriptions. An Event Grid output schema can't be used when using CloudEvents as an input schema because CloudEvents supports [extension attributes](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/primer.md#cloudevent-attribute-extensions) that aren't supported by the Event Grid schema.
5453

@@ -61,5 +60,130 @@ You can use Event Grid for both input and output of events in CloudEvents schema
6160

6261
For all event schemas, Event Grid requires validation when publishing to an Event Grid topic and when creating an event subscription. For more information, see [Event Grid security and authentication](security-authentication.md).
6362

64-
## Next steps
65-
See [How to use CloudEvents v1.0 schema with Event Grid](cloudevents-schema.md).
63+
### Input schema
64+
65+
You set the input schema for a custom topic when you create the custom topic by using the `input-schema` parameter.
66+
67+
For the Azure CLI, use:
68+
69+
```azurecli-interactive
70+
az eventgrid topic create --name demotopic -l westcentralus -g gridResourceGroup --input-schema cloudeventschemav1_0
71+
```
72+
73+
For PowerShell, use:
74+
75+
```azurepowershell-interactive
76+
New-AzEventGridTopic -ResourceGroupName gridResourceGroup -Location westcentralus -Name demotopic -InputSchema CloudEventSchemaV1_0
77+
```
78+
79+
### Output schema
80+
81+
You set the output schema when you create the event subscription by using the `event-delivery-schema` parameter.
82+
83+
For the Azure CLI, use:
84+
85+
```azurecli-interactive
86+
topicID=$(az eventgrid topic show --name demotopic -g gridResourceGroup --query id --output tsv)
87+
88+
az eventgrid event-subscription create --name demotopicsub --source-resource-id $topicID --endpoint <endpoint_URL> --event-delivery-schema cloudeventschemav1_0
89+
```
90+
91+
For PowerShell, use:
92+
```azurepowershell-interactive
93+
$topicid = (Get-AzEventGridTopic -ResourceGroupName gridResourceGroup -Name <topic-name>).Id
94+
95+
New-AzEventGridSubscription -ResourceId $topicid -EventSubscriptionName <event_subscription_name> -Endpoint <endpoint_URL> -DeliverySchema CloudEventSchemaV1_0
96+
```
97+
98+
<a name="azure-functions"></a>
99+
100+
## Use with Azure Functions
101+
102+
### Visual Studio or Visual Studio Code
103+
104+
If you're using Visual Studio or Visual Studio Code, and C# programming language to develop functions, make sure that you're using the latest [Microsoft.Azure.WebJobs.Extensions.EventGrid](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.EventGrid/) NuGet package (version **3.3.1** or above).
105+
106+
In Visual Studio, use the **Tools** -> **NuGet Package Manager** -> **Package Manager Console**, and run the `Install-Package` command (`Install-Package Microsoft.Azure.WebJobs.Extensions.EventGrid -Version 3.3.1`). Alternatively, right-click the project in the Solution Explorer window, and select **Manage NuGet Packages** menu to browse for the NuGet package, and install or update it to the latest version.
107+
108+
In VS Code, update the version number for the **Microsoft.Azure.WebJobs.Extensions.EventGrid** package in the **csproj** file for your Azure Functions project.
109+
110+
```xml
111+
<Project Sdk="Microsoft.NET.Sdk">
112+
<PropertyGroup>
113+
<TargetFramework>net6.0</TargetFramework>
114+
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
115+
</PropertyGroup>
116+
<ItemGroup>
117+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="3.3.1" />
118+
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
119+
</ItemGroup>
120+
<ItemGroup>
121+
<None Update="host.json">
122+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
123+
</None>
124+
<None Update="local.settings.json">
125+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
126+
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
127+
</None>
128+
</ItemGroup>
129+
</Project>
130+
```
131+
132+
The following example shows an Azure Functions version 3.x function that's developed in either Visual Studio or Visual Studio Code. It uses a `CloudEvent` binding parameter and `EventGridTrigger`.
133+
134+
```csharp
135+
using Azure.Messaging;
136+
using Microsoft.Azure.WebJobs;
137+
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
138+
using Microsoft.Extensions.Logging;
139+
140+
namespace Company.Function
141+
{
142+
public static class CloudEventTriggerFunction
143+
{
144+
[FunctionName("CloudEventTriggerFunction")]
145+
public static void Run(ILogger logger, [EventGridTrigger] CloudEvent e)
146+
{
147+
logger.LogInformation("Event received {type} {subject}", e.Type, e.Subject);
148+
}
149+
}
150+
}
151+
```
152+
153+
### Azure portal development experience
154+
155+
If you're using the Azure portal to develop an Azure function, follow these steps:
156+
157+
1. Update the name of the parameter in `function.json` file to `cloudEvent`.
158+
159+
```json
160+
{
161+
"bindings": [
162+
{
163+
"type": "eventGridTrigger",
164+
"name": "cloudEvent",
165+
"direction": "in"
166+
}
167+
]
168+
}
169+
```
170+
1. Update the `run.csx` file as shown in the following sample code.
171+
172+
```csharp
173+
#r "Azure.Core"
174+
175+
using Azure.Messaging;
176+
177+
public static void Run(CloudEvent cloudEvent, ILogger logger)
178+
{
179+
logger.LogInformation("Event received {type} {subject}", cloudEvent.Type, cloudEvent.Subject);
180+
}
181+
```
182+
183+
> [!NOTE]
184+
> For more information, see [Azure Event Grid trigger for Azure Functions](../azure-functions/functions-bindings-event-grid-trigger.md?tabs=in-process%2Cextensionv3&pivots=programming-language-csharp).
185+
186+
187+
## Related content
188+
- [CloudEvents](https://cloudevents.io/)
189+
- [Open specification](https://github.com/cloudevents/spec/blob/v1.0/spec.md)

articles/event-grid/cloudevents-schema.md

Lines changed: 0 additions & 203 deletions
This file was deleted.

articles/event-grid/concepts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The maximum allowed size for an event is 1 MB. Events over 64 KB are charged in
3333

3434
## Other formats
3535

36-
Event Grid also supports the proprietary [Event Grid schema](event-schema.md) format for [system events publishers](event-schema-api-management.md?tabs=cloud-event-schema). You can configure Event Grid to [deliver events using the CloudEvents](cloud-event-schema.md#event-grid-for-cloudevents) format.
36+
Event Grid also supports the proprietary [Event Grid schema](event-schema.md) format for [system events publishers](event-schema-api-management.md?tabs=cloud-event-schema). You can configure Event Grid to [deliver events using the CloudEvents](cloud-event-schema.md#configuration-for-cloudevents) format.
3737

3838
## Publishers
3939

0 commit comments

Comments
 (0)