Skip to content

Commit

Permalink
Add IdenttiyServer.Messaging.Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Jun 3, 2024
1 parent 9c12f84 commit 2f6295b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 41 deletions.
12 changes: 8 additions & 4 deletions src/IdentityServer/Messaging.Azure/EventHubSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@
using IdOps.IdentityServer.Abstractions;
using IdOps.Messages;
using MassTransit;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace IdOps.IdentityServer.Azure;

public sealed class EventHubSender : BackgroundService, IEventSenderWorker
{
private readonly IServiceProvider _serviceProvider;
private readonly ChannelReader<IdentityEventMessage> _channelReader;
private readonly IEventHubProducerProvider _producerProvider;

public EventHubSender(
IEventHubProducerProvider provider,
IServiceProvider serviceProvider,
ChannelReader<IdentityEventMessage> channelReader)
{
_producerProvider = provider;
_serviceProvider = serviceProvider;
_channelReader = channelReader;
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await Task.Yield();
await using AsyncServiceScope scope = _serviceProvider.CreateAsyncScope();
IEventHubProducerProvider provider =
scope.ServiceProvider.GetRequiredService<IEventHubProducerProvider>();

IEventHubProducer producer = await _producerProvider.GetProducer("identity-events");
IEventHubProducer producer = await provider.GetProducer("identity-events");

// we reuse the buffer to avoid allocations
var buffer = new IdentityEventMessage[50];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Azure.Identity;
using IdOps.IdentityServer.Abstractions;
using IdOps.IdentityServer.Azure;
using MassTransit;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -75,23 +74,6 @@ private static void RegisterEventHub(
throw new ApplicationException(
"EventHub configuration is missing. Please check your settings.");
}

if (eventHub.Storage is { } storageOption)
{
if (storageOption.Url is { } url)
{
k.Storage(new Uri(url), new DefaultAzureCredential());
}
else if (storageOption.ConnectionString is { } connectionString)
{
k.Storage(connectionString);
}
else
{
throw new ApplicationException(
"EventHub storage configuration is missing. Please check your settings.");
}
}
})
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/IdentityServer/Messaging.Azure/Options/EventHubOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ public class EventHubOptions
public string? ConnectionString { get; set; }

public string? Namespace { get; set; }

public EventStorageHubOptions? Storage { get; set; }
}

This file was deleted.

3 changes: 1 addition & 2 deletions src/IdentityServer/samples/Server/IdentityServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Messaging.AzureEventHub\Messaging.AzureEventHub.csproj" />
<ProjectReference Include="..\..\Messaging.AzureServiceBus\Messaging.AzureServiceBus.csproj" />
<ProjectReference Include="..\..\Messaging.Azure\Messaging.Azure.csproj" />
<ProjectReference Include="..\..\Messaging.RabbitMQ\Messaging.RabbitMQ.csproj" />
<ProjectReference Include="..\..\src\IdentityServer.Core\Core.csproj" />
<ProjectReference Include="..\..\src\Store.Mongo\Store.Mongo.csproj" />
Expand Down
10 changes: 4 additions & 6 deletions src/IdentityServer/samples/Server/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using IdOps.IdentityServer.AzureEventHub;
using IdOps.IdentityServer.AzureServiceBus;
using IdOps.IdentityServer.Azure;
using IdOps.IdentityServer.Events;
using IdOps.IdentityServer.RabbitMQ;
using IdOps.IdentityServer.Samples.DataSeeding;
Expand Down Expand Up @@ -50,12 +49,11 @@ public void ConfigureServices(IServiceCollection services)
case MessagingTransport.RabbitMq:
busBuilder.UseRabbitMq();
break;
case MessagingTransport.AzureServiceBus:
busBuilder.UseAzureServiceBus();
case MessagingTransport.Azure:
busBuilder.UseAzure();
break;
}

busBuilder.UseEventHub();

}).AddProfileService<SampleProfileService>();

services.AddSingleton<IIdOpsEventSink, ActivityEnricherSink>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public enum MessagingTransport
{
Memory,
RabbitMq,
AzureServiceBus
Azure
}
}

0 comments on commit 2f6295b

Please sign in to comment.