Arcus Event Grid Documentation

website·Indexed 32 days ago

https://eventgrid.arcus-azure.net/

Documentation for Arcus, providing support for publishing and deserializing Azure EventGrid, CloudEvents, and custom events. Features include endpoint validation for custom web hooks, support for Azure Event contracts, and tools for running integration tests. Supports versions up to v3.3.0.

Tokens
26.7K
Snippets
136
Records
161
Agent score
46%

What's inside Arcus

  1. Arcus.EventGrid Core Features

    v1.0.0

    Arcus.EventGrid v1.0.0 provides the following capabilities:

    • Publishing events to an Azure Event Grid Topic.
    • Handling the endpoint validation handshake required by Event Grid.
    • Pre-defined event contracts for a subset of Azure services.
  2. Arcus.EventGrid Library Capabilities

    v2.1.0

    The Arcus.EventGrid library (v2.1.0) provides the following functionality for Azure Event Grid integration:

    • Publishing events to an Event Grid Topic.
    • Handling the endpoint validation handshake required by Event Grid.
    • Event contracts for a subset of Azure services.
    • Tooling for writing integration tests.
    • Deserialization of events.
    • Support for creating custom events.
  3. Arcus.EventGrid.All Feature Overview

    v2.0.0

    The Arcus.EventGrid.All library (v2.0.0) provides the following capabilities:

    • Publishing events to an Azure Event Grid Topic.
    • Handling the endpoint validation handshake required by Event Grid.
    • Pre-defined event contracts for a subset of Azure services.
    • Support for creating custom event types.
  4. Arcus.EventGrid v2.2.0 Feature Overview

    v2.2.0

    The Arcus.EventGrid library provides the following core capabilities for interacting with Azure Event Grid:

    • Publishing events to an Event Grid Topic.
    • Handling the endpoint validation handshake required by Event Grid.
    • Deserializing incoming events.
    • Providing event contracts for a subset of Azure services.
    • Tooling for writing integration tests.
    • Support for creating custom events.
  5. Install Arcus.EventGrid.All via NuGet

    v2.0.0
    Install the Arcus.EventGrid.All package to enable publishing events to Event Grid Topics, handling endpoint validation handshakes, and using Azure service event contracts.
    Install-Package Arcus.EventGrid.All
  6. Verify received events using ServiceBusEventConsumerHost

    v2.3.0
    The ServiceBusEventConsumerHost allows you to subscribe to Azure Event Grid events on a custom topic and consume them in your tests. Because events flow asynchronously, the host provides a retry mechanism with exponential back-off to look up specific events by their ID.
    // Retrieve an event by ID with a specified number of retries
    _serviceBusEventConsumerHost.GetReceivedEvent(eventId, retryCount: 5)
  7. Implement subscription validation in Azure Functions

    To implement subscription validation in Azure Functions, install the Arcus.EventGrid.Security.AzureFunctions package and register the validation service in the Startup class. You can then inject IEventGridSubscriptionValidator into your function to manually handle CloudEvents handshakes or Azure Event Grid subscription events.
    PM> Install-Package Arcus.EventGrid.Security.AzureFunctions
    using Arcus.EventGrid.Security.Core;
    
    [assembly: FunctionsStartup(typeof(Startup))]
    public class Startup : FunctionsStartup
    {
        public void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddEventGridSubscriptionValidation();
        }
    }
    
    using Arcus.EventGrid.Security.Core.Validation;
    
    public class AzureMonitorScaledFunction
    {
        private readonly IEventGridSubscriptionValidator _eventGridSubscriptionValidator;
    
        public AzureMonitorScaledFunction(IEventGridSubscriptionValidator eventGridSubscriptionValidator)
        {
            _eventGridSubscriptionValidator = eventGridSubscriptionValidator;
        }
    
        [FunctionName("azure-monitor-scaled-app-event")]
        public async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", "options", Route = "v1/autoscale/azure-monitor/app")] HttpRequest request)
        {
            // Option #1: CloudEvents support (HTTP OPTIONS)
            if (HttpMethods.IsOptions(request.Method))
            {
                return _eventGridSubscriptionValidator.ValidateCloudEventsHandshakeRequest(request);
            }
    
            // Option #2: Azure EventGrid subscription event support (Aeg-Event-Type: SubscriptionValidation)
            if (request.Headers.TryGetValue("Aeg-Event-Type", out StringValues eventTypes) 
                && eventTypes.Contains("SubscriptionValidation"))
            {
                return await _eventGridSubscriptionValidator.ValidateEventGridSubscriptionEventRequestAsync(request);
            }
    
            return Ok();
        }
    }
  8. Install Arcus.EventGrid.All via NuGet

    v1.1.0
    Install the Arcus.EventGrid.All package to enable support for publishing events to an Event Grid Topic, handling endpoint validation handshakes, and utilizing event contracts for a subset of Azure services.
    Install-Package Arcus.EventGrid.All
  9. Deserialize custom typed events

    v3.2.0
    For custom event types, use EventGridParser.Parse<T> where T is your custom event implementation. The custom payload is accessible via the .GetPayload() method, while the original raw JSON payload can be accessed via the .Data property.
    using Arcus.EventGrid;
    using Arcus.EventGrid.Parsers;
    
    // Parse from custom event implementation
    EventGridBatch<NewCarRegistered> eventGridBatch = EventGridParser.Parse<NewCarRegistered>(rawEvent);
    
    // The event data type is wrapped inside an EventGridEvent<> instance
    NewCarRegistered eventGridMessage = eventGridBatch.Events.First();
    
    // Access the typed event payload
    CarEventData typedEventPayload = eventGridMessage.GetPayload();
    
    // Access the original raw JSON event payload
    object untypedEventPayload = eventGridMessage.Data;
  10. Publish custom events to Azure Event Grid Topics

    v1.0.1
    To publish custom events to a custom Azure Event Grid Topic, use the EventGridPublisher class from the Arcus.EventGrid.Publishing namespace. You must provide the topic endpoint and the authentication key to initialize the publisher.
    using Arcus.EventGrid.Publishing;
    
    // Initialize the publisher with the topic endpoint and authentication key
    var eventGridPublisher = EventGridPublisher.Create(topicEndpoint, endpointKey);
    
    // Define event details
    string licensePlate = "1-TOM-337";
    string eventSubject = $"/cars/{licensePlate}";
    string eventId = Guid.NewGuid().ToString();
    
    // Create the event payload
    var @event = new NewCarRegistered(eventId, eventSubject, licensePlate);
    
    // Publish the event
    await eventGridPublisher.Publish(
        eventSubject, 
        eventType: "NewCarRegistered", 
        data: new [] { @event }, 
        id: eventId
    );
  11. Deserialize CloudEvent events

    v3.0.0
    The Arcus.EventGrid package supports deserializing CloudEvents using the official C# SDK. Use EventParser.Parse on the CloudEvent JSON string, and the resulting events can be cast to the CloudEvent type.
    using Arcus.EventGrid;
    using Arcus.EventGrid.Parsers;
    using CloudNative.CloudEvents;
    
    string cloudEventJson = ...;
    EventBatch<Event> eventBatch = EventParser.Parse(cloudEventJson);
    var events = eventBatch.Events;
    
    // Cast implicitly to CloudEvent
    CloudEvent cloudEvent = events.First();
    
    // Or cast explicitly
    CloudEvent cloudEventExplicit = events.First().AsCloudEvent();