You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-bindings-event-grid.md
+34-48
Original file line number
Diff line number
Diff line change
@@ -195,15 +195,22 @@ Here's the binding data in the *function.json* file:
195
195
Here's the Python code:
196
196
197
197
```python
198
+
import json
198
199
import logging
199
-
import azure.functions as func
200
200
201
+
import azure.functions as func
201
202
202
203
defmain(event: func.EventGridEvent):
203
-
logging.info("Python Event Grid function processed a request.")
204
-
logging.info(" Subject: %s", event.subject)
205
-
logging.info(" Time: %s", event.event_time)
206
-
logging.info(" Data: %s", event.get_json())
204
+
205
+
result = json.dumps({
206
+
'id': event.id,
207
+
'data': event.get_json(),
208
+
'topic': event.topic,
209
+
'subject': event.subject,
210
+
'event_type': event.event_type,
211
+
})
212
+
213
+
logging.info('Python EventGrid trigger processed an event: %s', result)
207
214
```
208
215
209
216
# [Java](#tab/java)
@@ -305,19 +312,19 @@ For a complete example, see C# example.
305
312
306
313
# [C# Script](#tab/csharp-script)
307
314
308
-
**TODO**
315
+
Attributes are not supported by C# Script.
309
316
310
317
# [JavaScript](#tab/javascript)
311
318
312
-
**TODO**
319
+
Attributes are not supported by JavaScript.
313
320
314
321
# [Python](#tab/python)
315
322
316
-
**TODO**
323
+
Attributes are not supported by Python.
317
324
318
325
# [Java](#tab/java)
319
326
320
-
**TODO**
327
+
The [EventGridTrigger](https://github.com/Azure/azure-functions-java-library/blob/master/src/main/java/com/microsoft/azure/functions/annotation/EventGridTrigger.java) annotation allows you to declaratively configure an Event Grid binding by providing configuration values. See the [example](#example) and [configuration](#configuration) sections for more detail.
321
328
322
329
---
323
330
@@ -345,23 +352,33 @@ In Azure Functions 2.x and higher, you also have the option to use the following
345
352
*`Microsoft.Azure.EventGrid.Models.EventGridEvent`- Defines properties for the fields common to all event types.
346
353
347
354
> [!NOTE]
348
-
> 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)
355
+
> 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`.
349
356
350
357
# [C# Script](#tab/csharp-script)
351
358
352
-
**TODO**
359
+
In Azure Functions 1.x, you can use the following parameter types for the Event Grid trigger:
360
+
361
+
*`JObject`
362
+
*`string`
363
+
364
+
In Azure Functions 2.x and higher, you also have the option to use the following parameter type for the Event Grid trigger:
365
+
366
+
*`Microsoft.Azure.EventGrid.Models.EventGridEvent`- Defines properties for the fields common to all event types.
367
+
368
+
> [!NOTE]
369
+
> 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)
353
370
354
371
# [JavaScript](#tab/javascript)
355
372
356
-
The parameter named by the *function.json*`name` property has a reference to the event object.
373
+
The Event Grid instance is available via the parameter configured in the *function.json*file's `name` property.
357
374
358
375
# [Python](#tab/python)
359
376
360
-
**TODO**
377
+
The Event Grid instance is available via the parameter configured in the *function.json* file's `name` property, typed as `func.EventGridEvent`.
361
378
362
379
# [Java](#tab/java)
363
380
364
-
**TODO**
381
+
The Event Grid event instance is available via the parameter associated to the `EventGridTrigger` attribute, typed as an `EventSchema`. See the [example](#example) for more detail.
365
382
366
383
---
367
384
@@ -661,12 +678,10 @@ If you use an HTTP trigger, you have to write code for what the Event Grid trigg
661
678
* Sends a validation response to a [subscription validation request](../event-grid/security-authentication.md#webhook-event-delivery).
662
679
* Invokes the function once per element of the event array contained in the request body.
663
680
664
-
For information about the URL to use for invoking the function locally or when it runs in Azure, see the [HTTP trigger binding reference documentation](functions-bindings-http-webhook.md)
681
+
For information about the URL to use for invoking the function locally or when it runs in Azure, see the [HTTP trigger binding reference documentation](functions-bindings-http-webhook.md).
665
682
666
683
### Event Grid schema
667
684
668
-
**TODO**
669
-
670
685
# [C#](#tab/csharp)
671
686
672
687
The following sample C# code for an HTTP trigger simulates Event Grid trigger behavior. Use this example for events delivered in the Event Grid schema.
@@ -707,36 +722,6 @@ public static async Task<HttpResponseMessage> Run(
707
722
}
708
723
```
709
724
710
-
The following sample JavaScript code for an HTTP trigger simulates Event Grid trigger behavior. Use this example for events delivered in the Event Grid schema.
711
-
712
-
```javascript
713
-
module.exports=function (context, req) {
714
-
context.log('JavaScript HTTP trigger function processed a request.');
715
-
716
-
var messages =req.body;
717
-
// If the request is for subscription validation, send back the validation code.
718
-
if (messages.length>0&& messages[0].eventType=="Microsoft.EventGrid.SubscriptionValidationEvent") {
Your event-handling code goes inside the loop through the `messages` array.
739
-
740
725
### CloudEvents schema
741
726
742
727
The following sample C# code for an HTTP trigger simulates Event Grid trigger behavior. Use this example for events delivered in the CloudEvents schema.
@@ -776,13 +761,14 @@ public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLeve
776
761
returnreq.CreateResponse(HttpStatusCode.OK);
777
762
}
778
763
```
764
+
779
765
# [C# Script](#tab/csharp-script)
780
766
781
767
**TODO**
782
768
783
769
# [JavaScript](#tab/javascript)
784
770
785
-
The following sample JavaScript code for an HTTP trigger simulates Event Grid trigger behavior. Use this example for events delivered in the CloudEvents schema.
771
+
The following sample simulates the Event Grid trigger behavior. Use this example for events delivered in the CloudEvents schema.
0 commit comments