The code in this repository shows publish and subscribe to events using event grid in .NET Aspire. The code is made up of 2 applications, EventGridDemo.Publisher and EventGridDemo.Api. The publisher application publishes events to the event grid topic, and the API application listens for events from the event grid topic.
The /hook
endpoint is used for validating the webhook. When Event Grid creates a new subscription, it sends a validation event to the webhook. The validation event contains a validationCode property. The application reads the validationCode from the first event and returns it as a response.
The AppHost projects creates the eventgrid topic, web hook subscription, sets up the role assignment and orchestrates the deployment of the publisher and api.
Event grid subscriptions require the endpoint to be live. In order to get the application deployed, there must be a 2 step deployment process. This application has uses a bootstrapper container and
a bootstrap container app to deploy the application. The bootstrap container is configured in main.bicep, which is auto-generated by using azd infra synth
.
See https://github.com/Azure/azure-dev/issues/3931 for more details.