Skip to content

Commit 3286633

Browse files
authored
Merge pull request #221244 from spelluru/spegridcloudfunc1212
Portal dev experience - function
2 parents d6f0730 + 928db63 commit 3286633

File tree

1 file changed

+57
-25
lines changed

1 file changed

+57
-25
lines changed

articles/event-grid/cloudevents-schema.md

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,8 @@ If you're already familiar with Event Grid, you might be aware of the endpoint v
125125
<a name="azure-functions"></a>
126126

127127
## Use with Azure Functions
128-
The following example shows an Azure Functions version 3.x function that uses a `CloudEvent` binding parameter and `EventGridTrigger`.
129128

130-
```csharp
131-
using Azure.Messaging;
132-
using Microsoft.Azure.WebJobs;
133-
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
134-
using Microsoft.Extensions.Logging;
135-
136-
namespace Company.Function
137-
{
138-
public static class CloudEventTriggerFunction
139-
{
140-
[FunctionName("CloudEventTriggerFunction")]
141-
public static void Run(
142-
ILogger logger,
143-
[EventGridTrigger] CloudEvent e)
144-
{
145-
logger.LogInformation("Event received {type} {subject}", e.Type, e.Subject);
146-
}
147-
}
148-
}
149-
```
150-
151-
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).
152-
153-
### Microsoft.Azure.WebJobs.Extensions.EventGrid
129+
### Visual Studio or Visual Studio Code
154130

155131
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.2.1** or above).
156132

@@ -180,6 +156,62 @@ In VS Code, update the version number for the **Microsoft.Azure.WebJobs.Extensio
180156
</Project>
181157
```
182158

159+
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`.
160+
161+
```csharp
162+
using Azure.Messaging;
163+
using Microsoft.Azure.WebJobs;
164+
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
165+
using Microsoft.Extensions.Logging;
166+
167+
namespace Company.Function
168+
{
169+
public static class CloudEventTriggerFunction
170+
{
171+
[FunctionName("CloudEventTriggerFunction")]
172+
public static void Run(
173+
ILogger logger,
174+
[EventGridTrigger] CloudEvent e)
175+
{
176+
logger.LogInformation("Event received {type} {subject}", e.Type, e.Subject);
177+
}
178+
}
179+
}
180+
```
181+
182+
### Azure portal development experience
183+
184+
If you're using the Azure portal to develop an Azure function, follow these steps:
185+
186+
1. Update the name of the parameter in `function.json` file to `cloudEvent`.
187+
188+
```json
189+
{
190+
"bindings": [
191+
{
192+
"type": "eventGridTrigger",
193+
"name": "cloudEvent",
194+
"direction": "in"
195+
}
196+
]
197+
}
198+
```
199+
1. Update the `run.csx` file as shown in the following sample code.
200+
201+
```csharp
202+
#r "Azure.Core"
203+
204+
using Azure.Messaging;
205+
206+
public static void Run(CloudEvent cloudEvent, ILogger logger)
207+
{
208+
logger.LogInformation("Event received {type} {subject}", cloudEvent.Type, cloudEvent.Subject);
209+
}
210+
```
211+
212+
> [!NOTE]
213+
> 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).
214+
183215

184216
## Next steps
185217

0 commit comments

Comments
 (0)