Skip to content

Commit f7ab204

Browse files
authored
Merge pull request #41668 from tdykstra/eg
update for package and template changes
2 parents b8de13d + 8fbc518 commit f7ab204

File tree

1 file changed

+19
-32
lines changed

1 file changed

+19
-32
lines changed

articles/azure-functions/functions-bindings-event-grid.md

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,8 @@ If you prefer, you can use an HTTP trigger to handle Event Grid Events; see [Use
3434

3535
The Event Grid trigger is provided in the [Microsoft.Azure.WebJobs.Extensions.EventGrid](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.EventGrid) NuGet package. Source code for the package is in the [azure-functions-eventgrid-extension](https://github.com/Azure/azure-functions-eventgrid-extension) GitHub repository.
3636

37-
<!--
38-
If you want to bind to the `Microsoft.Azure.EventGrid.Models.EventGridEvent` type instead of `JObject`, install the [Microsoft.Azure.EventGrid](https://www.nuget.org/packages/Microsoft.Azure.EventGrid) package.
39-
-->
40-
4137
[!INCLUDE [functions-package](../../includes/functions-package.md)]
4238

43-
[!INCLUDE [functions-package-versions](../../includes/functions-package-versions.md)]
44-
4539
## Example
4640

4741
See the language-specific example for an Event Grid trigger:
@@ -54,12 +48,12 @@ For an HTTP trigger example, see [How to use HTTP trigger](#use-an-http-trigger-
5448

5549
### C# example
5650

57-
The following example shows a [C# function](functions-dotnet-class-library.md) that binds to `JObject`:
51+
The following example shows a Functions 1.x [C# function](functions-dotnet-class-library.md) that binds to `JObject`:
5852

5953
```cs
6054
using Microsoft.Azure.WebJobs;
61-
using Microsoft.Azure.WebJobs.Host;
6255
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
56+
using Microsoft.Azure.WebJobs.Host;
6357
using Newtonsoft.Json;
6458
using Newtonsoft.Json.Linq;
6559

@@ -76,30 +70,26 @@ namespace Company.Function
7670
}
7771
```
7872

79-
<!--
80-
The following example shows a [C# function](functions-dotnet-class-library.md) that binds to `EventGridEvent`:
73+
The following example shows a Functions 2.x [C# function](functions-dotnet-class-library.md) that binds to `EventGridEvent`:
8174

8275
```cs
76+
using Microsoft.Azure.EventGrid.Models;
8377
using Microsoft.Azure.WebJobs;
84-
using Microsoft.Azure.WebJobs.Host;
8578
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
79+
using Microsoft.Azure.WebJobs.Host;
8680

8781
namespace Company.Function
8882
{
8983
public static class EventGridTriggerCSharp
9084
{
9185
[FunctionName("EventGridTest")]
92-
public static void EventGridTest([EventGridTrigger] Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
86+
public static void EventGridTest([EventGridTrigger]EventGridEvent eventGridEvent, TraceWriter log)
9387
{
94-
log.Info("C# Event Grid function processed a request.");
95-
log.Info($"Subject: {eventGridEvent.Subject}");
96-
log.Info($"Time: {eventGridEvent.EventTime}");
97-
log.Info($"Data: {eventGridEvent.Data.ToString()}");
88+
log.Info(eventGridEvent.Data.ToString());
9889
}
9990
}
10091
}
10192
```
102-
-->
10393

10494
For more information, see [Packages](#packages), [Attributes](#attributes), [Configuration](#configuration), and [Usage](#usage).
10595

@@ -122,7 +112,7 @@ Here's the binding data in the *function.json* file:
122112
}
123113
```
124114

125-
Here's C# script code that binds to `JObject`:
115+
Here's Functions 1.x C# script code that binds to `JObject`:
126116

127117
```cs
128118
#r "Newtonsoft.Json"
@@ -136,26 +126,17 @@ public static void Run(JObject eventGridEvent, TraceWriter log)
136126
}
137127
```
138128

139-
<!--
140-
Here's C# script code that binds to `EventGridEvent`:
129+
Here's Functions 2.x C# script code that binds to `EventGridEvent`:
141130

142131
```csharp
143-
#r "Newtonsoft.Json"
144-
#r "Microsoft.Azure.WebJobs.Extensions.EventGrid"
145132
#r "Microsoft.Azure.EventGrid"
146-
147-
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
148-
Using Microsoft.Azure.EventGrid.Models;
133+
using Microsoft.Azure.EventGrid.Models;
149134

150135
public static void Run(EventGridEvent eventGridEvent, TraceWriter log)
151136
{
152-
log.Info("C# Event Grid function processed a request.");
153-
log.Info($"Subject: {eventGridEvent.Subject}");
154-
log.Info($"Time: {eventGridEvent.EventTime}");
155-
log.Info($"Data: {eventGridEvent.Data.ToString()}");
137+
log.Info(eventGridEvent.Data.ToString());
156138
}
157139
```
158-
-->
159140

160141
For more information, see [Packages](#packages), [Attributes](#attributes), [Configuration](#configuration), and [Usage](#usage).
161142

@@ -218,11 +199,17 @@ The following table explains the binding configuration properties that you set i
218199

219200
## Usage
220201

221-
For C# and F# functions, you can use the following parameter types for the Event Grid trigger:
202+
For C# and F# functions in Azure Functions 1.x, you can use the following parameter types for the Event Grid trigger:
222203

223204
* `JObject`
224205
* `string`
225-
* `Microsoft.Azure.WebJobs.Extensions.EventGrid.EventGridEvent`- Defines properties for the fields common to all event types. **This type is deprecated**, but its replacement is not published to NuGet yet.
206+
207+
For C# and F# functions in Azure Functions 2.x, you also have the option to use the following parameter type for the Event Grid trigger:
208+
209+
* `Microsoft.Azure.EventGrid.Models.EventGridEvent`- Defines properties for the fields common to all event types.
210+
211+
> [!NOTE]
212+
> In Functions v1 if you try to bind to `Microsoft.Azure.WebJobs.Extensions.EventGrid.EventGridEvent`, the compiler will display a "deprecated" message and advise you to use `Microsoft.Azure.EventGrid.Models.EventGridEvent` instead. To use the newer type, reference the [Microsoft.Azure.EventGrid](https://www.nuget.org/packages/Microsoft.Azure.EventGrid) NuGet package and fully qualify the `EventGridEvent` type name by prefixing it with `Microsoft.Azure.EventGrid.Models`. For information about how to reference NuGet packages in a C# script function, see [Using NuGet packages](functions-reference-csharp.md#using-nuget-packages)
226213
227214
For JavaScript functions, the parameter named by the *function.json* `name` property has a reference to the event object.
228215

0 commit comments

Comments
 (0)