0
votes

I've connected my blob storage account to Event Grid, via an Event Hub subscription, and can see the events from uploaded blobs.

But I was hoping to be able to pass some metadata with each received event, so I can relate the event back to a foreign key (customer identifier) without having to do extra work on each event.

Is this possible? I couldn't see anything in the API docs regarding this.

1

1 Answers

3
votes

Based on the Azure Event Grid event schema for Blob storage there is no metadata properties in the Blob storage event data.

Note, there is only one specific case passing some metadata from the AEG Subscription to its subscriber such as a query string of the webhook event handler endpoint (e.g. HttpTrigger function).

Solution for your scenario is using an EventGridTrigger function (subscriber) with output binding to the Event Hub.

The following example shows a lightweight implementation of the event message mediator using the EventGridTrigger function:

    [FunctionName("Function1")]
    [return: EventHub("%myEventHub%", Connection = "AzureEventHubConnectionString")]
    public  async Task<JObject> Run([EventGridTrigger]JObject ed, ILogger log)
    {
        // original event message
        log.LogInformation(ed.ToString());

        // place for event data enrichment
        var metadata = new { metadata = "ABCD", abcd = 12345 };

        // enrich data object
        ed["data"]["url"]?.Parent.AddAfterSelf(new JProperty("subscription", JObject.FromObject(metadata)));

        // show after mediation
        log.LogWarning(ed.ToString());

        // forward to the Event Hub
        return await Task.FromResult(ed);
    }

and the log output from the Event Hub:

enter image description here