The Workleap Azure Event Grid Emulator is a .NET 9.0 ASP.NET Core application that emulates Azure Event Grid for local development. It supports both push delivery (webhooks) and pull delivery (queue-based) models for EventGridEvents and CloudEvents.
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
-
Bootstrap, build, and test the repository:
- Install .NET 9.0 SDK:
- Download the install script:
curl -sSL https://dot.net/v1/dotnet-install.sh -o dotnet-install.sh - (Optional but recommended) Verify the script's integrity.
- Run the script:
bash dotnet-install.sh --channel 9.0 --install-dir ~/.dotnet - (Alternatively, use your OS package manager if available: see official docs.)
- Download the install script:
- Add to PATH:
export PATH="$HOME/.dotnet:$PATH" - Build and test:
pwsh -File Build.ps1 - Alternative build commands (from src/ directory):
dotnet clean -c Release src/dotnet build -c Release src/dotnet test -c Release src/ --no-restore
- Install .NET 9.0 SDK:
-
Run the Event Grid emulator locally:
- ALWAYS run the bootstrapping steps first.
- Navigate to:
cd src/EventGridEmulator - Start emulator:
dotnet run-- starts on http://localhost:6500 - Health check:
curl -X GET http://localhost:6500/healthreturns "Healthy" - Default configuration supports both push webhooks and pull subscriptions
- Application logs show loaded topics and subscribers on startup
-
Format and lint code:
- Format code:
dotnet format(from src/ directory) - Verify formatting:
dotnet format --verify-no-changes(from src/ directory) -- fails if formatting is needed - The project uses extensive .editorconfig rules for C# code analysis
- NOTE: Some files currently have formatting issues (final newlines, encoding) that need to be fixed
- Format code:
- ALWAYS manually validate changes by running the complete build and test suite.
- ALWAYS test the application by starting it and verifying the health endpoint responds.
- ALWAYS test basic event publishing functionality after making changes:
-
Start the emulator:
dotnet runin src/EventGridEmulator/ -
Test health:
curl -X GET http://localhost:6500/health -
Publish test event:
curl -X POST http://localhost:6500/topicfoobar/api/events \ -H "Content-Type: application/json" \ -d @- <<EOF [ { "id": "test123", "subject": "test-subject", "eventType": "test.event", "dataVersion": "1.0", "data": { "message": "test data" } } ] EOF
-
Verify events appear in application logs for pull subscriptions
-
- You cannot build or test the Docker image in this environment due to certificate restrictions.
- Always run
dotnet formatbefore you are done or the CI (.github/workflows/ci.yml) will fail.
- Configuration file: The emulator requires an
appsettings.jsonfile to define topics and subscriptions - Push delivery: Events are forwarded to configured webhook URLs
- Pull delivery: Events are queued and retrieved via API calls using
pull://subscription format - Event filtering: Supports filtering by event type through the
Filtersconfiguration section - The emulator runs on port 6500 by default and exposes these endpoints:
POST /{topic}/api/events- Publish events to a topic (Custom Topics)POST /topics/{topic}:publish- Publish events to a namespace topicPOST /topics/{topic}/eventsubscriptions/{subscription}:receive- Pull events from subscriptionPOST /topics/{topic}/eventsubscriptions/{subscription}:acknowledge- Acknowledge eventsPOST /topics/{topic}/eventsubscriptions/{subscription}:release- Release events back to queuePOST /topics/{topic}/eventsubscriptions/{subscription}:reject- Reject eventsGET /health- Health check endpoint
The following are key project directories and files to understand:
src/
├── EventGridEmulator/ # Main application
│ ├── Program.cs # Application entry point and DI setup
│ ├── EventHandling/ # Event processing logic
│ ├── Configuration/ # Configuration options and validation
│ ├── Network/ # HTTP client and networking
│ ├── appsettings.json # Development configuration
│ └── Dockerfile # Docker image definition
├── EventGridEmulator.Tests/ # Integration and unit tests
├── Samples/ # Example publisher and subscriber apps
│ ├── Publisher/ # Sample event publisher
│ └── Subscriber/ # Sample webhook subscriber
└── EventGridEmulator.sln # Solution file
global.json- Specifies .NET 9.0.304 SDK requirementsrc/Directory.Build.props- Common MSBuild properties for all projectsBuild.ps1- PowerShell build script used by CI.github/workflows/ci.yml- GitHub Actions CI pipelinesrc/.editorconfig- Extensive C# coding standards and analyzer rules
- Uses PowerShell-based build script for consistency across platforms
- CI runs on Ubuntu using the Build.ps1 script
- Docker image targets linux-musl-x64 runtime on Alpine Linux
- Test framework: xUnit with Microsoft.AspNetCore.Mvc.Testing for integration tests
- Code analysis: Workleap.DotNet.CodingStandards package provides extensive rules
- EventGridEvents: Traditional Azure Event Grid format
- CloudEvents: CNCF CloudEvents v1.0 specification
- Both formats support the same delivery models (push/pull)
- Namespace topics only support CloudEvents format
- Publisher (
src/Samples/Publisher/): Demonstrates how to publish EventGridEvents to multiple topics- Run with:
dotnet run(from Publisher directory) - Publishes to both
activities-egandcomments-egtopics - Shows proper use of EventGridPublisherClient with dummy credentials
- Run with:
- Subscriber (
src/Samples/Subscriber/): Mock webhook server that responds to different scenarios- Run with:
dotnet run(from Subscriber directory) - Provides endpoints that return different HTTP status codes for testing retry behavior
- Includes slow endpoint (1-minute delay) for testing timeout handling
- Essential for testing push delivery scenarios
- Run with:
- The emulator starts quickly (2.5 seconds) for rapid development iteration
- Use the health endpoint to verify the application is running correctly
- Sample applications in
Samples/directory demonstrate usage patterns - Tests provide examples of both push and pull delivery scenarios
- Configuration hot-reload works when not running in Docker containers
- Always test both EventGridEvent and CloudEvent formats when making changes to event handling
- Docker build may fail in sandboxed environments due to certificate issues - this is normal and expected