arcus-azure / arcus.eventgrid

Azure Event Grid development in a breeze
https://eventgrid.arcus-azure.net/
MIT License
17 stars 6 forks source link

Use new Azure SDK clients for Azure EventGrid publishing #243

Closed stijnmoreels closed 2 years ago

stijnmoreels commented 2 years ago

Is your feature request related to a problem? Please describe. Currently, we use a dedicated IEventGridPublisher interface to publish evens (raw, CloudEvent, EventGridEvent) to an Azure EventGrid resource. Since the Azure SDK is moving towards a system where clients are registered in the application, we should also move towards that directions. We already did some work on adding correlation dependency tracking on the ServiceBusSender, which can also be injected via this system, but since we use a dedicated publisher for EventGrid, we can't use this new Azure SDK client registration system, yet.

Describe the solution you'd like Provide a custom implementation of the EventGridPublisherClient that tracks the EventGrid dependency and enriches the event with the operation parent ID and transaction ID. The consumer should be able to override the way these properties are added to the event, as they should be defined as custom delivery properties in Azure EventGrid. The options provided should inherit from the EventGridPublisherClientOptions and make sure that we can configure the property names for the correlation information and the resilient functionality (exceptional back-off, circuit-breaker) which are now available in our custom EventGrid publisher.

stijnmoreels commented 2 years ago

@pim-simons @fgheysels

You agree on this? Some pseudo example of what I'm trying to achieve:

var services = new ServiceCollection();
string authenticationKeySecretName = "Arcus_EventGrid_AuthenticationKey";
string authenticationKey = "@uthent1cationKey";
services.AddSecretStore(stores => stores.AddInMemory(authenticationKeySecretName, authenticationKey));

services.AddAzureClients(builder => 
{
    // New:
    builder.AddEventGridPublisherClient("https://my-eventgrid-topic-endpoint", authenticationKeySecretName);

    // Currently already available in Microsoft.Extensions.Azure: https://www.nuget.org/packages/Microsoft.Extensions.Azure
    builder.AddEventGridPublisherClient(new Uri("https://my-eventgrid-topic-endpoint", new AzureKeyCredential(authenticationKey));
});

// Usage
public class MyService
{
    public MyService(IAzureClientFactory<EventGridPublisherClient> factory)
    {
        EventGridPublisherClient client = factory.CreateClient("Default");
    }
}

Eventually, people would be able to configure dependency correlation and resilience right from the registration and it would not show in the actual application code. Our implementation would also make use of the secret store, instead of relying on the application configuration.

pim-simons commented 2 years ago

I find it a bit hard to offer some good feedback on this since I haven't used this a lot, but from your description and pseudo code it seems like a good idea.