Publishing event from Azure DevOps to Azure Event Grid

try the following:

https://<yourtopic>.<region>.eventgrid.azure.net/api/events?aeg-sas-key=<your url encoded key>

and the following is an Event Schema of the payload:

[
  {
    "topic": string,
    "subject": string,
    "id": string,
    "eventType": string,
    "eventTime": string,
    "data":{
      object-unique-to-each-publisher
    },
    "dataVersion": string,
    "metadataVersion": string
  }
]

UPDATE:

The example of the HttpTrigger function with output binding to the AEG custom topic:

run.csx:

#r "Newtonsoft.Json"
#r "Microsoft.Azure.EventGrid"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.Azure.EventGrid.Models;

public static async Task<IActionResult> Run(JObject body, IAsyncCollector<EventGridEvent> outputEvents, ILogger log)
{
    log.LogInformation($"{body.ToString(Formatting.Indented)}");

    EventGridEvent ege = new EventGridEvent() {
        Topic = null,
        Id = (string)body["id"],
        EventType = (string)body["eventType"],
        EventTime = (DateTime)body["createdDate"],
        Data = body,
        DataVersion = "1",
        Subject = "abcd"
    };
    await outputEvents.AddAsync(ege);

    return (ActionResult)new NoContentResult(); 
}

function.json:

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "body",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
         "post"
      ]
    },
    {
      "type": "eventGrid",
      "direction": "out",
      "name": "outputEvents",
      "topicEndpointUri": "AEG_TOPIC_XX_ENDPOINT",
      "topicKeySetting": "AEG_TOPIC_XX_KEY"
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ]
}

enter code here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top