The new way of doing this seems to be CloudEvent
from the Azure.Messaging
namespace.
(A side note is that the data properties are case-sensitive, I'm not sure if they were before.)
public async Task CustomerCreated([EventGridTrigger] CloudEvent eventGridEvent, FunctionContext functionContext)
{
}
UPDATE:
This breaks when deploying to Azure and receiving events from a real event grid with an Azure Function as endpoints. But works fine when testing locally using ngrok and webhook. Back to square one.
After endless googling with outdated examples I found a note in this document, pointing to this example showing that you need to create a custom type (looking just like the EventGridEvent).
After testing I found that this actually works:
Pass a string
instead of EventGridEvent
and parse the actual event with the utility function from EventGridEvent
.
[Function(nameof(CustomerCreated))]
public async Task CustomerCreated([EventGridTrigger] string data, FunctionContext functionContext)
{
var eventGridEvent = EventGridEvent.Parse(BinaryData.FromString(data));
}
Another related caveat is that you can't create the function from the portal but need to run it from the command line like:
az eventgrid event-subscription create
(The resource id:s can be found at http://resources.azure.com/)
Hello Microsoft;
Running Azure Functions on .NET5 doesn't feel very GA with this approach. I really hope to be able to pass typed objects like EventGridEvent from other Azure services with official libraries.
I really think that the EventGridEvent on .NET5/dotnet-isolated should be compatible with Azure Functions at the same level as on previous .NET versions and as in the public examples.