Skip to content

Add Azure Event Grid integration with CloudEvents support #1299

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

belljun3395
Copy link

@belljun3395 belljun3395 commented Aug 18, 2025

Azure Event Grid Trigger Sample

Overview

This PR adds a comprehensive Azure Event Grid trigger sample that demonstrates integration with Spring Cloud Function using CloudEvents v1.0 specification. The sample showcases event processing patterns for modern cloud-native applications.

This contribution is also related to #1279

What's Included

Core Implementation

  • EventGridDemoApplication: Main Spring Boot application with two Spring Cloud Functions
    • processEvent: Processes incoming CloudEvents with detailed logging
    • createEvent: Creates CloudEvents from payload maps
  • EventGridHandler: Azure Function HTTP trigger handler that supports:
    • CloudEvents v1.0 format (structured and binary mode)
    • Event Grid native format with automatic conversion
    • Webhook validation according to CloudEvents specification

Key Features

  • Multi-format Support: Handles both CloudEvents and Event Grid formats seamlessly
  • Webhook Validation: Implements proper Azure Event Grid subscription validation
  • Binary Mode Support: Processes CloudEvents in both structured (JSON) and binary (HTTP headers) modes
  • Automatic Conversion: Converts Event Grid format events to CloudEvents for consistent processing
  • Comprehensive Testing: Unit tests covering validation, format detection, and event processing paths

Configuration & Deployment

  • Maven configuration for Azure Functions deployment
  • Local development setup with Azure Functions Core Tools
  • Complete Azure resource setup scripts
  • Detailed README with usage examples

Technical Implementation Details

The sample demonstrates several important patterns:

  1. Event Format Detection: Automatically detects and handles different event formats based on content-type and headers
  2. CloudEvents Standards Compliance: Full support for CloudEvents v1.0 specification
  3. Spring Cloud Function Integration: Uses function catalog for loose coupling between Azure Functions and business logic
  4. Error Handling: Graceful error handling with appropriate HTTP status codes

Testing Strategy

The implementation includes comprehensive unit tests that verify:

  • Webhook validation with and without origin headers
  • Event format detection (CloudEvents vs Event Grid)
  • Subscription validation event handling
  • Binary mode CloudEvent processing

Benefits

  • Standardization: Uses CloudEvents specification for interoperability
  • Flexibility: Supports multiple event formats and delivery modes
  • Production Ready: Includes proper error handling, logging, and testing
  • Educational Value: Demonstrates best practices for Azure Event Grid integration

This sample provides a solid foundation for developers building event-driven applications with Azure Event Grid and Spring Cloud Function.

@belljun3395 belljun3395 force-pushed the chore/westus-eventgrid branch from 4f3408b to c44c287 Compare August 18, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant