From 85454e27bc67858ef82a58d3a4126bda0872f06c Mon Sep 17 00:00:00 2001 From: Rick Date: Thu, 14 Nov 2024 08:28:07 -0600 Subject: [PATCH] remove ASB preview --- demo/ConsoleDemo/ConsoleDemo.csproj | 1 - demo/ConsoleDemo/Demo/AsbDemo.cs | 76 ------ docs/content/concepts.md | 2 +- docs/content/introduction.md | 2 +- .../ApolloBuilder.cs | 42 +++- .../Apollo.Providers.ASB.csproj | 23 -- src/Apollo.Providers.ASB/AsbConfig.cs | 15 -- src/Apollo.Providers.ASB/AsbPublisher.cs | 21 -- .../AsbSubscriptionProvider.cs | 40 --- .../AsbTopicSubscription.cs | 235 ------------------ .../BusResourceManager.cs | 75 ------ src/Apollo.Providers.ASB/Setup.cs | 28 --- src/Apollo.Providers.ASB/Utils.cs | 61 ----- src/Apollo.sln | 7 - 14 files changed, 42 insertions(+), 586 deletions(-) delete mode 100644 demo/ConsoleDemo/Demo/AsbDemo.cs delete mode 100644 src/Apollo.Providers.ASB/Apollo.Providers.ASB.csproj delete mode 100644 src/Apollo.Providers.ASB/AsbConfig.cs delete mode 100644 src/Apollo.Providers.ASB/AsbPublisher.cs delete mode 100644 src/Apollo.Providers.ASB/AsbSubscriptionProvider.cs delete mode 100644 src/Apollo.Providers.ASB/AsbTopicSubscription.cs delete mode 100644 src/Apollo.Providers.ASB/BusResourceManager.cs delete mode 100644 src/Apollo.Providers.ASB/Setup.cs delete mode 100644 src/Apollo.Providers.ASB/Utils.cs diff --git a/demo/ConsoleDemo/ConsoleDemo.csproj b/demo/ConsoleDemo/ConsoleDemo.csproj index 7fea031..dc22083 100644 --- a/demo/ConsoleDemo/ConsoleDemo.csproj +++ b/demo/ConsoleDemo/ConsoleDemo.csproj @@ -8,7 +8,6 @@ - diff --git a/demo/ConsoleDemo/Demo/AsbDemo.cs b/demo/ConsoleDemo/Demo/AsbDemo.cs deleted file mode 100644 index 9dcc78e..0000000 --- a/demo/ConsoleDemo/Demo/AsbDemo.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Text; -using Apollo; -using Apollo.Configuration; -using Apollo.Extensions.Microsoft.Hosting; -using Apollo.Providers.ASB; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Serilog; - -namespace ConsoleDemo.Demo; - -public class AsbDemo -{ - public static async ValueTask Demo() - { - var anonConfig = new EndpointConfig - { - Subject = "topic-test", // topic name - ConsumerName = "Sandbox.Test", // subscription name - EndpointName = "Topic Test", // display only when subject is sent - }; - - var asbConfig = new AsbConfig - { - ConnectionString = "", - // SubscriptionName = "", - // CreateMissingResources = false - }; - - var builder = Host.CreateApplicationBuilder(); - builder.Services - .AddApollo(apolloBuilder => apolloBuilder - .AddHandler(anonConfig, Handle) - .AddAsbProvider(asbConfig) - ); - //.AddScoped(); - - var host = builder.Build(); - using var scope = host.Services.CreateScope(); - var serviceProvider = scope.ServiceProvider; - var apollo = serviceProvider.GetRequiredService(); - - var publisher = apollo.CreatePublisher(anonConfig); - - await Task.WhenAll( - publisher.Broadcast(new TestEvent("test 1"), CancellationToken.None), - publisher.Broadcast(new TestEvent("test 2"), CancellationToken.None), - publisher.Broadcast(new TestEvent("test 3"), CancellationToken.None), - publisher.Broadcast(new TestEvent("test 4"), CancellationToken.None), - publisher.Broadcast(new TestEvent("test 5"), CancellationToken.None) - ); - - Log.Verbose("Press any key to exit"); - Console.ReadKey(); - } - - static int count; // demo concurrency - - private static Task Handle(ApolloContext context, CancellationToken token) - { - Log.Warning($"Anonymous handler received: {count++}"); - Log.Debug("Headers"); - foreach (var header in context.Headers) - { - Log.Debug("{Key}: {Value}", header.Key, header.Value); - } - - Log.Debug("Payload"); - if (context.Data != null) - Log.Debug(Encoding.UTF8.GetString(context.Data)); - - - // let me see some messages before they spam through - return Task.Delay(15000); - } -} \ No newline at end of file diff --git a/docs/content/concepts.md b/docs/content/concepts.md index bdc3f9a..2176fbe 100644 --- a/docs/content/concepts.md +++ b/docs/content/concepts.md @@ -2,7 +2,7 @@ ### Overview -Apollo is a flexible library originally designed for NATS that has since evolved to support a generic in-memory provider and an in-preview provider for Azure Service Bus (ASB). At its core, Apollo simplifies communication between different parts of your system by offering a plug-and-play mechanism for routing messages dynamically between local and remote endpoints. +Apollo is a flexible library designed for NATS, with support for a generic in-memory provider. To extend Apollo, developers can implement their own custom providers. ### Key Concepts and Components diff --git a/docs/content/introduction.md b/docs/content/introduction.md index 1f518c2..3dfba4c 100644 --- a/docs/content/introduction.md +++ b/docs/content/introduction.md @@ -1,3 +1,3 @@ ## Introduction -Welcome to the Apollo documentation! Apollo is designed for easy integration with various messaging providers. Whether you need in-memory messaging for simplicity, the robust messaging features of NATS, or the enterprise capabilities of Azure Service Bus, Apollo has you covered. +Welcome to the Apollo documentation! Apollo is designed for easy integration with various messaging providers, including in-memory messaging for simplicity or the robust features of NATS. You can also implement your own custom messaging provider for other use cases. diff --git a/src/Apollo.Extensions.Microsoft.Hosting/ApolloBuilder.cs b/src/Apollo.Extensions.Microsoft.Hosting/ApolloBuilder.cs index 559a166..45bdfe8 100644 --- a/src/Apollo.Extensions.Microsoft.Hosting/ApolloBuilder.cs +++ b/src/Apollo.Extensions.Microsoft.Hosting/ApolloBuilder.cs @@ -13,18 +13,23 @@ public interface IApolloBuilder IApolloBuilder WithDefaultConsumerName(string consumerName); IApolloBuilder WithDefaultNamespace(string defaultNamespace); IApolloBuilder CreateMissingResources(bool createMissingResources = true); + IApolloBuilder WithAckStrategy(AckStrategy ackStrategy); IApolloBuilder PublishOnly(bool publishOnly = true); IApolloBuilder AddEndpoint(EndpointConfig config) where TEndpoint : class; IApolloBuilder AddHandler(EndpointConfig config, Func handler); IApolloBuilder WithEndpointProvider(IEndpointProvider endpointProvider); IApolloBuilder WithEndpointProvider() where TProvider : class, IEndpointProvider; + IApolloBuilder WithSubscriberProvider(ISubscriptionProvider subscriberProvider); + IApolloBuilder WithSubscriberProvider() where TProvider : class, ISubscriptionProvider; + IApolloBuilder WithProviderPublisher(IProviderPublisher providerPublisher); + IApolloBuilder WithProviderPublisher() where TPublisher : class, IProviderPublisher; } internal class ApolloBuilder : IApolloBuilder { public IServiceCollection Services { get; } private ApolloConfig config = new(); - + public ApolloBuilder(IServiceCollection services) { Services = services; @@ -75,6 +80,12 @@ public IApolloBuilder CreateMissingResources(bool createMissingResources = true) return this; } + public IApolloBuilder WithAckStrategy(AckStrategy ackStrategy) + { + config.AckStrategy = ackStrategy; + return this; + } + /// /// Set the service to publish only mode /// @@ -120,7 +131,34 @@ public IApolloBuilder WithEndpointProvider(IEndpointProvider endpointProvider) /// public IApolloBuilder WithEndpointProvider() where TProvider : class, IEndpointProvider { - Services.TryAddSingleton(); + Services.TryAddSingleton(); + Services.TryAddSingleton(serviceProvider => serviceProvider.GetRequiredService()); + return this; + } + + public IApolloBuilder WithSubscriberProvider(ISubscriptionProvider subscriberProvider) + { + Services.TryAddSingleton(subscriberProvider); + return this; + } + + public IApolloBuilder WithSubscriberProvider() where TProvider : class, ISubscriptionProvider + { + Services.TryAddSingleton(); + Services.TryAddSingleton(serviceProvider => serviceProvider.GetRequiredService()); + return this; + } + + public IApolloBuilder WithProviderPublisher(IProviderPublisher providerPublisher) + { + Services.TryAddSingleton(providerPublisher); + return this; + } + + public IApolloBuilder WithProviderPublisher() where TPublisher : class, IProviderPublisher + { + Services.TryAddSingleton(); + Services.TryAddSingleton(serviceProvider => serviceProvider.GetRequiredService()); return this; } diff --git a/src/Apollo.Providers.ASB/Apollo.Providers.ASB.csproj b/src/Apollo.Providers.ASB/Apollo.Providers.ASB.csproj deleted file mode 100644 index 9b90330..0000000 --- a/src/Apollo.Providers.ASB/Apollo.Providers.ASB.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - net8.0 - enable - enable - - - - RickDotNet.Apollo.Providers.ASB - - - - - - - - - - - - - diff --git a/src/Apollo.Providers.ASB/AsbConfig.cs b/src/Apollo.Providers.ASB/AsbConfig.cs deleted file mode 100644 index 80823a2..0000000 --- a/src/Apollo.Providers.ASB/AsbConfig.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Apollo.Providers.ASB; - -public record AsbConfig -{ - public required string ConnectionString { get; init; } - //public required string TenantId { get; set; } - //public required string ClientId { get; set; } - //public string? ClientSecret { get; set; } - public string AuthorityHost { get; set; } = "https://login.windows.net"; // AzureAuthorityHosts.AzurePublicCloud - - // public required string TopicName { get; init; } - // public required string SubscriptionName { get; init; } - // public bool IsDurable => true; - // public bool CreateMissingResources { get; set; } -} \ No newline at end of file diff --git a/src/Apollo.Providers.ASB/AsbPublisher.cs b/src/Apollo.Providers.ASB/AsbPublisher.cs deleted file mode 100644 index 77819a5..0000000 --- a/src/Apollo.Providers.ASB/AsbPublisher.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Apollo.Abstractions; - -namespace Apollo.Providers.ASB; - -internal class AsbPublisher : IPublisher -{ - public Task Send(TCommand commandMessage, CancellationToken cancellationToken) where TCommand : ICommand - { - throw new NotImplementedException(); - } - - public Task Broadcast(TEvent eventMessage, CancellationToken cancellationToken) where TEvent : IEvent - { - throw new NotImplementedException(); - } - - public Task Request(TRequest requestMessage, CancellationToken cancellationToken) where TRequest : IRequest - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/src/Apollo.Providers.ASB/AsbSubscriptionProvider.cs b/src/Apollo.Providers.ASB/AsbSubscriptionProvider.cs deleted file mode 100644 index cafe9d5..0000000 --- a/src/Apollo.Providers.ASB/AsbSubscriptionProvider.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Apollo.Abstractions; -using Apollo.Configuration; -using Microsoft.Extensions.Logging; - -namespace Apollo.Providers.ASB; - - -internal class AsbSubscriptionProvider : ISubscriptionProvider -{ - private readonly ApolloConfig apolloConfig; - private readonly BusResourceManager resourceManager; - private readonly ILoggerFactory loggerFactory; - - public AsbSubscriptionProvider(ApolloConfig apolloConfig, BusResourceManager resourceManager, ILoggerFactory loggerFactory) - { - this.apolloConfig = apolloConfig; - this.resourceManager = resourceManager; - this.loggerFactory = loggerFactory; - } - - public ISubscription AddSubscription(SubscriptionConfig subscriptionConfig, Func handler) - { - return new AsbTopicSubscription( - apolloConfig, - subscriptionConfig, - resourceManager, - loggerFactory.CreateLogger(), - handler - ); - } -} - -public class AsbSubscription //: ISubscription -{ - // virtual OnDisposeAsync? - for the caller to do some stuff - public ValueTask DisposeAsync() - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/src/Apollo.Providers.ASB/AsbTopicSubscription.cs b/src/Apollo.Providers.ASB/AsbTopicSubscription.cs deleted file mode 100644 index c714eca..0000000 --- a/src/Apollo.Providers.ASB/AsbTopicSubscription.cs +++ /dev/null @@ -1,235 +0,0 @@ -using Apollo.Abstractions; -using Apollo.Configuration; -using Azure.Messaging.ServiceBus; -using Azure.Messaging.ServiceBus.Administration; -using Microsoft.Extensions.Logging; - -namespace Apollo.Providers.ASB; - -internal class AsbTopicSubscription : ISubscription -{ - private readonly ApolloConfig apolloConfig; - private readonly SubscriptionConfig subscriptionConfig; - private readonly ServiceBusClient client; - private readonly ILogger logger; - private readonly BusResourceManager resourceManager; - private readonly Func handler; - private readonly string topicName; - private readonly Dictionary topicNameMapping; - - public AsbTopicSubscription( - ApolloConfig apolloConfig, - SubscriptionConfig subscriptionConfig, - BusResourceManager resourceManager, - ILogger logger, - Func handler - ) - { - this.apolloConfig = apolloConfig; - this.subscriptionConfig = subscriptionConfig; - this.resourceManager = resourceManager; - this.client = this.resourceManager.Client; - this.logger = logger; - this.handler = handler; - - // if they send a subject, don't adjust case - // this will all be addressed during a config refactor - var toLower = string.IsNullOrEmpty(subscriptionConfig.Subject); - topicName = Utils.GetTopic(subscriptionConfig, toLower); - - - // trim .> and .* from the end of the subject - var trimmedSubject = topicName.TrimWildEnds().ToLower(); - - // we do want to lower case them for lookup - topicNameMapping = - subscriptionConfig.MessageTypes.ToDictionary(x => $"{trimmedSubject.ToLower()}.{x.Name.ToLower()}", x => x); - } - - public async Task Subscribe(CancellationToken cancellationToken) - { - try - { - // this was built for NATS so we need to strip the wildcard - logger.LogWarning("Subscribing to {Topic}", topicName); - logger.LogTrace("CreateMissingResources: {CreateMissingResources}", - subscriptionConfig.CreateMissingResources); - - // ASB only lets the subscription name be 50 characters - var safeConsumerLength = 50 - subscriptionConfig.ConsumerName.Length; - var safeConsumerName = subscriptionConfig.ConsumerName.Length > safeConsumerLength - ? subscriptionConfig.ConsumerName[..safeConsumerLength] - : subscriptionConfig.ConsumerName; - - var subscriptionOptions = new CreateSubscriptionOptions(topicName, safeConsumerName) - { - // the original subscription name for full reference - UserMetadata = subscriptionConfig.ConsumerName - }; - - if (!subscriptionConfig.IsDurable) - { - subscriptionOptions.DefaultMessageTimeToLive = TimeSpan.FromMinutes(1); - subscriptionOptions.AutoDeleteOnIdle = TimeSpan.FromMinutes(5); - } - - var topicExists = await resourceManager.TopicExistsAsync(subscriptionOptions.TopicName, cancellationToken); - if (!topicExists) - { - if (!subscriptionConfig.CreateMissingResources) - throw new InvalidOperationException($"Missing topic: {subscriptionOptions.TopicName}"); - logger.LogTrace("Creating topic {TopicName}", subscriptionOptions.TopicName); - await resourceManager.CreateTopicAsync(subscriptionOptions.TopicName, cancellationToken); - } - - var subscriptionExists = await resourceManager.SubscriptionExistsAsync(subscriptionOptions.TopicName, - subscriptionOptions.SubscriptionName, cancellationToken); - if (!subscriptionExists) - { - if (!subscriptionConfig.CreateMissingResources) - throw new InvalidOperationException( - $"Missing subscription ({subscriptionOptions.SubscriptionName}) on topic ({subscriptionOptions.SubscriptionName})"); - - logger.LogTrace("Creating subscription {SubscriptionName} on topic {TopicName}", - subscriptionOptions.SubscriptionName, subscriptionOptions.TopicName); - await resourceManager.CreateSubscriptionAsync(subscriptionOptions, cancellationToken); - } - - var identifier = apolloConfig.InstanceId; - await using var processor = client.CreateProcessor( - subscriptionOptions.TopicName, - subscriptionOptions.SubscriptionName, - new ServiceBusProcessorOptions - { - AutoCompleteMessages = false, - //ReceiveMode = receiveMode, - Identifier = identifier, - } - ); - - // configure the message and error handler to use - processor.ProcessMessageAsync += ProcessMessage; - processor.ProcessErrorAsync += ErrorHandler; - - await processor.StartProcessingAsync(cancellationToken); - await Task.Delay(Timeout.Infinite, cancellationToken); - } - catch (TaskCanceledException) - { - logger.LogWarning("MessageProcessor TaskCanceledException"); - } - catch (Exception ex) - { - logger.LogError(ex, "Error subscribing to {EndpointSubject}", subscriptionConfig.Subject); - } - - return; - - Task ErrorHandler(ProcessErrorEventArgs arg) - { - logger.LogError(arg.Exception, "Error processing message"); - return Task.CompletedTask; - } - - async Task ProcessMessage(ProcessMessageEventArgs args) - { - try - { - logger.LogTrace("Processing message {MessageId}", args.Message.MessageId); - - if (subscriptionConfig.AckStrategy == AckStrategy.AutoAck) - await args.CompleteMessageAsync(args.Message, cancellationToken); - - await ActuallyProcessMessage(args.Message); - logger.LogTrace("Completed message {MessageId}", args.Message.MessageId); - - if (subscriptionConfig.AckStrategy == AckStrategy.Default) - await args.CompleteMessageAsync(args.Message, cancellationToken); - } - catch (Exception ex) - { - logger.LogError(ex, "Error processing message {MessageId}", args.Message.MessageId); - await args.AbandonMessageAsync(args.Message, cancellationToken: cancellationToken); - throw; // need to make sure this doesn't crash the processor - } - } - - Task ActuallyProcessMessage(ServiceBusReceivedMessage msg) - { - //var messageTypeMetaData = msg.ApplicationProperties["message-type"].ToString(); - - - var message = new ApolloMessage - { - Subject = topicName, //$"{msg.Subject}", this was null - Data = msg.Body.ToArray() - }; - - var handlerOnly = subscriptionConfig.EndpointType == null; - if (!handlerOnly) - { - // note, this is an NServiceBus specific test - // this will ultimately be an Apollo defined property and will - // be apollo based. For the NSB use-case, we'll likely create a - // specific NsbSubscription that handles the nuance there - if (msg.ApplicationProperties.TryGetValue("NServiceBus.EnclosedMessageTypes", - out var messageTypeMetaData) && messageTypeMetaData is not null) - { - var type = GetSkinnyNsbType(messageTypeMetaData); - if (!string.IsNullOrEmpty(type)) - message.Subject = $"{message.Subject}.{messageTypeMetaData}"; - } - } - - logger.LogDebug("Application Properties"); - foreach (var property in msg.ApplicationProperties) - { - var value = property.Value?.ToString(); - - logger.LogDebug("{Key}: {Value}", property.Key, value); - if (value == null) continue; - - if (!message.Headers.TryAdd(property.Key, value)) - message.Headers[property.Key] = value; - } - - if (msg.Body != null) - { - var json = msg.Body.ToString(); - logger.LogTrace("JSON:\n{Json}", json); - - // we lowercase it in the constructor as well - topicNameMapping.TryGetValue(message.Subject.ToLower(), out var messageType); - message.MessageType = messageType; - - var replyFunc = msg.ReplyTo != null - ? new Func( - (response, innerCancel) => - { - var sender = client.CreateSender($"{msg.ReplyTo}.{msg.ReplyToSessionId}"); - var responseMessage = new ServiceBusMessage(response) - { - SessionId = msg - .ReplyToSessionId // Set the SessionId to the ReplyToSessionId from the request - }; - return sender.SendMessageAsync(responseMessage, innerCancel); - } - ) - : null; - - return handler(new ApolloContext(message, replyFunc), cancellationToken); - } - - return Task.CompletedTask; - } - - string GetSkinnyNsbType(object type) - { - var typeString = type.ToString() ?? ""; - var firstComma = typeString.IndexOf(','); - return firstComma > 0 - ? typeString[..firstComma] - : typeString; - } - } -} \ No newline at end of file diff --git a/src/Apollo.Providers.ASB/BusResourceManager.cs b/src/Apollo.Providers.ASB/BusResourceManager.cs deleted file mode 100644 index 56c0179..0000000 --- a/src/Apollo.Providers.ASB/BusResourceManager.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Azure.Core; -using Azure.Messaging.ServiceBus; -using Azure.Messaging.ServiceBus.Administration; - -namespace Apollo.Providers.ASB; - -internal class BusResourceManager : IAsyncDisposable -{ - public ServiceBusClient Client { get; } - private readonly ServiceBusAdministrationClient adminClient; - - public BusResourceManager(string connectionString, TokenCredential creds) - { - Client = new ServiceBusClient(connectionString, creds); - adminClient = new ServiceBusAdministrationClient(connectionString, creds); - } - - public async Task QueueExistsAsync(string name, CancellationToken cancellationToken = default) - { - // we'll eventually be caching these results - // await is to avoid the goofiness until then - return await adminClient.QueueExistsAsync(name, cancellationToken); - } - - public async Task TopicExistsAsync(string topicName, CancellationToken cancellationToken) - { - return await adminClient.TopicExistsAsync(topicName, cancellationToken); - } - - public Task CreateQueueAsync(string queueName, CancellationToken cancellationToken) - => adminClient.CreateQueueAsync(queueName, cancellationToken); - - public Task CreateTopicAsync(string topicName, CancellationToken cancellationToken) - => adminClient.CreateTopicAsync(topicName, cancellationToken); - - public Task CreateSubscriptionAsync(CreateSubscriptionOptions createSubscriptionOptions, - CancellationToken cancellationToken) - { - return adminClient.CreateSubscriptionAsync(createSubscriptionOptions, cancellationToken); - } - - public async Task SubscriptionExistsAsync(string topicName, string subscriptionName, - CancellationToken cancellationToken) - { - return await adminClient.SubscriptionExistsAsync(topicName, subscriptionName, cancellationToken); - } - - public async Task CreateReplyTopicAndSubscriptionAsync(string topicName, string subscriptionName, - CancellationToken cancellationToken) - { - // pass in filters based on handled message types - // then create a rule - // var rule = new CreateRuleOptions() - // { - // Name = "RequestTypeFilter", - // Filter = new SqlRuleFilter($"Subject IN '{requestTypes}'") - // }; - - var subscriptionOptions = new CreateSubscriptionOptions(topicName, subscriptionName) { RequiresSession = true }; - - if (!await TopicExistsAsync(topicName, cancellationToken)) - await CreateTopicAsync(topicName, cancellationToken); - - if (!await SubscriptionExistsAsync(topicName, subscriptionName, cancellationToken)) - await CreateSubscriptionAsync(subscriptionOptions, cancellationToken); - } - - public async ValueTask DisposeAsync() - { - if (Client is IDisposable disposableClient) - disposableClient.Dispose(); - - await Client.DisposeAsync(); - } -} \ No newline at end of file diff --git a/src/Apollo.Providers.ASB/Setup.cs b/src/Apollo.Providers.ASB/Setup.cs deleted file mode 100644 index 21a648e..0000000 --- a/src/Apollo.Providers.ASB/Setup.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Apollo.Abstractions; -using Apollo.Extensions.Microsoft.Hosting; -using Azure.Core; -using Azure.Identity; -using Microsoft.Extensions.DependencyInjection; - -namespace Apollo.Providers.ASB; - -public static class Setup -{ - [Obsolete("The ASB provider is not fully implemented .", false)] - public static IApolloBuilder AddAsbProvider(this IApolloBuilder builder, AsbConfig asbConfig) - { - builder.Services.AddSingleton(asbConfig); - builder.Services.AddSingleton(new BusResourceManager(asbConfig.ConnectionString, GetCreds(asbConfig))); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(x => x.GetRequiredService()); - - - return builder; - } - - private static TokenCredential GetCreds(AsbConfig asbConfig) - { - // local dev - return new DefaultAzureCredential() { }; - } -} \ No newline at end of file diff --git a/src/Apollo.Providers.ASB/Utils.cs b/src/Apollo.Providers.ASB/Utils.cs deleted file mode 100644 index 2ec2ea1..0000000 --- a/src/Apollo.Providers.ASB/Utils.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Apollo.Configuration; - -namespace Apollo.Providers.ASB; - -internal static class Utils -{ - public static string GetTopic(PublishConfig config, bool toLower = true) - => GetTopic((config.Namespace, config.EndpointName, EndpointType: null, config.Subject)) - .TrimWildEnds(); - - public static string GetTopic(SubscriptionConfig config, bool toLower = true) - => GetTopic((config.Namespace, config.EndpointName, config.EndpointType, config.Subject)); - - private static string GetTopic( - (string? Namespace, string? EndpointName, Type? EndpointType, string? EndpointSubject) config, bool toLower = true) - { - // this entire class is carry over from POC - // need to take a proper look at Apollo subject mapping - // and stop forcing square pegs into round holes - if (string.IsNullOrEmpty(config.Namespace) - && string.IsNullOrEmpty(config.EndpointName) - && string.IsNullOrEmpty(config.EndpointSubject)) - { - throw new ArgumentException("Namespace, EndpointName, or EndpointSubject must be set"); - } - - var endpoint = config.EndpointSubject; - if (string.IsNullOrEmpty(endpoint)) - endpoint = Slugify(config.EndpointName); - - if (string.IsNullOrEmpty(endpoint)) - endpoint = Slugify(config.EndpointType?.Name); - - - var result = $"{endpoint?.TrimWildEnds()}"; - if (!string.IsNullOrEmpty(config.Namespace)) - result = $"{config.Namespace}.{result}"; - - return toLower ? result.ToLower() : result; - } - - private static string? Slugify(string? input) - { - return input?.ToLower().Replace(" ", "-"); - } - - /// - /// Trims '.>' and '.*' from the end of the string - /// - /// - /// - public static string TrimWildEnds(this string subject) - => subject.TrimEnd('>').TrimEnd('*').TrimEnd('.'); - public static string CleanStreamName(this string streamName) - { - return streamName.Replace(".", "_") - .Replace("*", "") - .Replace(">", "") - .TrimEnd('_'); - } -} \ No newline at end of file diff --git a/src/Apollo.sln b/src/Apollo.sln index 5d00038..77ac554 100644 --- a/src/Apollo.sln +++ b/src/Apollo.sln @@ -4,8 +4,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apollo", "Apollo\Apollo.csp EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FB5261E1-CCA4-4F5A-B87B-F8F48B14A249}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apollo.Providers.ASB", "Apollo.Providers.ASB\Apollo.Providers.ASB.csproj", "{7EADC5D9-61C2-4417-A4C0-14CADDBED7DE}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{1D6230D5-90E9-4E63-81D4-4C6B8149E318}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDemo", "..\demo\ConsoleDemo\ConsoleDemo.csproj", "{EDFC8FC8-B94A-4894-9C96-2A369FE02397}" @@ -34,10 +32,6 @@ Global {9BDF9386-096A-43B1-AE6B-85EDE94AC743}.Debug|Any CPU.Build.0 = Debug|Any CPU {9BDF9386-096A-43B1-AE6B-85EDE94AC743}.Release|Any CPU.ActiveCfg = Release|Any CPU {9BDF9386-096A-43B1-AE6B-85EDE94AC743}.Release|Any CPU.Build.0 = Release|Any CPU - {7EADC5D9-61C2-4417-A4C0-14CADDBED7DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7EADC5D9-61C2-4417-A4C0-14CADDBED7DE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7EADC5D9-61C2-4417-A4C0-14CADDBED7DE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7EADC5D9-61C2-4417-A4C0-14CADDBED7DE}.Release|Any CPU.Build.0 = Release|Any CPU {EDFC8FC8-B94A-4894-9C96-2A369FE02397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EDFC8FC8-B94A-4894-9C96-2A369FE02397}.Debug|Any CPU.Build.0 = Debug|Any CPU {EDFC8FC8-B94A-4894-9C96-2A369FE02397}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -65,7 +59,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {9BDF9386-096A-43B1-AE6B-85EDE94AC743} = {FB5261E1-CCA4-4F5A-B87B-F8F48B14A249} - {7EADC5D9-61C2-4417-A4C0-14CADDBED7DE} = {FB5261E1-CCA4-4F5A-B87B-F8F48B14A249} {EDFC8FC8-B94A-4894-9C96-2A369FE02397} = {1D6230D5-90E9-4E63-81D4-4C6B8149E318} {9C0E4983-FE32-4DC4-AFBA-0EA5BA9A0B3C} = {FB5261E1-CCA4-4F5A-B87B-F8F48B14A249} {4CB2ED5A-4DA7-4908-A9D8-7D8B345E4007} = {30C30859-8FA1-4399-9556-0D435B6357DB}