Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support strongly typed event data #11

Closed
drub0y opened this issue Aug 22, 2017 · 9 comments
Closed

Support strongly typed event data #11

drub0y opened this issue Aug 22, 2017 · 9 comments
Labels

Comments

@drub0y
Copy link

drub0y commented Aug 22, 2017

Currently EventGridEvent is designed with its Data property as a JObject which will force everyone downstream to get into dealing with converting that into their own strong types using the JSON.NET APIs themselves.

I propose supporting an EventGridEvent<T> where the Data property would now be T. This would allow people to use a parameter such as EventGridEvent<CustomerProfileUpdated> and it would "just work". Simultaneously we can keep the existing, default EventGridEvent by simply changing it to be a subclass of EventGridEvent<JObject> that effectively locks it into JObject for people who might choose to work with that model instead.

@ChristianWeyer
Copy link

Is there anything like this planned?
.cc @fabiocav .cc @jeffhollan

@jeffhollan
Copy link

We just use the EventGrid .net SDK to surface the trigger so it’s likely a better ask for the event grid SDK team. If the SDK supported it functions would “inherit” that functionality. I’ll ping them on this ask and reference the discussion.

@adrianknight89
Copy link

@jeffhollan Can you give us an update on this? Also, I'd like to see enums for eventType. Coding against strings looks unreliable to me.

@iamalexmang
Copy link

An update would be highly appreciated, @jeffhollan.
I realize this is not in the Functions' turf, but I appreciate that you could add some weight to this.
I believe that it is childish that the event which is getting a strongly typed object must be read using a key value pair instead.
What's mostly annoying is the the only available sample using custom data literally leverages this functionality, but it fires an http-triggered function instead (which is far from ideal for the purpose of the sample): Event Grid triggered functions just be just that, not an http triggered function which pulls the event data, imho.

@jeffhollan
Copy link

Sure let me send this to the Event Grid team and see if any thoughts on what would be required here and if something that can be committed

@krb3d
Copy link

krb3d commented Feb 22, 2021

Hello there. Any updates on this topic?

@fnandocontreras
Copy link

+1 Nice to have this feature

@MattMinke
Copy link

MattMinke commented Mar 30, 2022

So the EventGrid client library (NuGet: "Microsoft.Azure.EventGrid") has a EventGridSubscriber that supports the ability to add custom mappings that will be used during deserialization. With this you can then Cast the Data property to the type you are interested in. While not exactly what is being asked for this might provide the insight to someone more familiar with the inner working of Azure functions and how the EventGridTrigger works.

public void Example(System.IO.Stream inbound)
{
    var eventGridSubscriber = new Microsoft.Azure.EventGrid.EventGridSubscriber();

    eventGridSubscriber.AddOrUpdateCustomEventMapping(
        typeof(MyEvent).FullName,
        typeof(MyEvent));

    var events = eventGridSubscriber.DeserializeEventGridEvents(inbound);

    var myEvent = (MyEvent)events.First().Data;

}

NOTE: The Microsoft.Azure.EventGrid package has been deprecated in favor of Azure.Messaging.EventGrid however I think Azure functions are still using the Microsoft.Azure.EventGrid package
https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventgrid/Azure.Messaging.EventGrid/MigrationGuide.md#deserializing-events-and-data

Additional reference material:

@shreyabatra4
Copy link

This is available in the new version of bindings (3.x), reference here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants