diff --git a/docs/preview/02-Features/02-message-handling/01-service-bus.md b/docs/preview/02-Features/02-message-handling/01-service-bus.md index a49c19b0..c058f8e0 100644 --- a/docs/preview/02-Features/02-message-handling/01-service-bus.md +++ b/docs/preview/02-Features/02-message-handling/01-service-bus.md @@ -60,7 +60,7 @@ Once the message handler is created, you can very easily register it: ```csharp using Microsoft.Extensions.DependencyInjection; -public class Startup +public class Program { public void ConfigureServices(IServiceCollection services) { @@ -113,12 +113,15 @@ We would like that this handler only processed the message when the context cont ```csharp using Microsoft.Extensions.DependencyInjection; -public class Startup +public class Program { public void ConfigureServices(IServiceCollection services) { services.AddServiceBusTopicMessagePump(...) - .WithServiceBusMessageHandler(context => context.Properties["MessageType"].ToString() == "Order"); + .WithServiceBusMessageHandler(options => + { + options.AddMessageContextFilter(context => context.Properties["MessageType"].ToString() == "Order")); + }); } } ``` @@ -156,20 +159,22 @@ The registration of these message body serializers can be done just as easily as ```csharp using Microsoft.Extensions.DependencyInjection; -public class Startup +public class Program { public void ConfigureServices(IServiceCollection services) { - // Register the message body serializer in the dependency container where the dependent services will be injected. services.AddServiceBusTopicMessagePump(...) - .WitServiceBusMessageHandler(..., messageBodySerializer: new OrderBatchMessageBodySerializer()); - - // Register the message body serializer in the dependency container where the dependent services are manually injected. - services.AddServiceBusTopicMessagePump(...) - .WithServiceBusMessageHandler(..., messageBodySerializerImplementationFactory: serviceProvider => + .WitServiceBusMessageHandler(options => { - var logger = serviceProvider.GetService>(); - return new OrderBatchMessageHandler(logger); + // Option #1 + options.AddMessageBodySerializer(new OrderBatchMessageBodySerializer()); + + // Option #2 + options.AddMessageBodySerializer(serviceProvider => + { + var logger = serviceProvider.GetService>(); + return new OrderBatchMessageHandler(logger); + }); }); } } @@ -209,12 +214,15 @@ public class OrderMessageHandler : IAzureServiceBusMessageHandler using Microsoft.Extensions.DependencyInjection; // Message handler registration -public class Startup +public class Program { public void ConfigureServices(IServiceCollection services) { services.AddServiceBusTopicMessagePump(...) - .WithServiceMessageHandler((Order order) => order.Type == Department.Sales); + .WithServiceMessageHandler(options => + { + options.AddMessageBodyFilter((Order order) => order.Type == Department.Sales)); + }); } } ``` @@ -435,10 +443,6 @@ public class Startup // this job instance in a multi-instance deployment (default: guid). options.JobId = Guid.NewGuid().ToString(); - // The format of the message correlation used when receiving Azure Service Bus messages. - // (default: W3C). - options.Routing.Correlation.Format = MessageCorrelationFormat.Hierarchical; - // The name of the operation used when tracking the request telemetry. // (default: Process) options.Routing.Correlation.OperationName = "Order"; @@ -491,10 +495,6 @@ public class Startup // this job instance in a multi-instance deployment (default: guid). options.JobId = Guid.NewGuid().ToString(); - // The format of the message correlation used when receiving Azure Service Bus messages. - // (default: W3C). - options.Routing.Correlation.Format = MessageCorrelationFormat.Hierarchical; - // The name of the operation used when tracking the request telemetry. // (default: Process) options.Routing.Correlation.OperationName = "Order"; diff --git a/docs/preview/02-Features/02-message-handling/02-service-bus-azure-functions.md b/docs/preview/02-Features/02-message-handling/02-service-bus-azure-functions.md deleted file mode 100644 index 4664a990..00000000 --- a/docs/preview/02-Features/02-message-handling/02-service-bus-azure-functions.md +++ /dev/null @@ -1,232 +0,0 @@ ---- -title: "Azure Service Bus message handling for Azure Functions" -layout: default ---- - -This article describes how you can use Arcus' message handler concept with Azure Functions; allowing you to more easily port your business logic from/to Azure Functions. - -# Azure Service Bus message handling for Azure Functions -While our default message pump system provides a way to receive, route, and handle incoming Service Bus messages which are, unfortunately, not supported in Azure Functions. -Today, Azure Functions acts as a message receiver meaning that the function is triggered when a message is available but does not handle message routing and handling. However, in this case, it acts as the message pump. - -Following terms are used: -- **Message handler**: implementation that processes the received message from an Azure Service Bus queue or topic subscription. Message handlers are created by implementing the `IAzureServiceBusMessageHandler`. This message handler will be called upon when a message is available in the Azure Service Bus queue or on the topic subscription. -- **Message router**: implementation that delegates the received Azure Service Bus message to the correct message handler. - -That's why we extracted our message routing functionality so you can call it directly from your Azure Function. - -![Azure Functions message handling](/media/az-func-message-handling.png) - -We will walk you through the process of using message handlers with Azure Functions: - -## Installation -To use the following described features, install the following package: -```shell -PM > Install-Package -Name Arcus.Messaging.AzureFunctions.ServiceBus -``` - -## Receive Azure Service Bus message in an Azure Function -Here's an example of how an Azure Function receives an Azure Service Bus message from a topic: - -```csharp -public class MessageProcessingFunction -{ - [FunctionName("message-processor")] - public void Run( - [ServiceBusTrigger("%TopicName%", "%SubscriptionName%", Connection = "ServiceBusConnectionString")] Message message, - ILogger log) - { - // Processing message... - } -} -``` - -## Declaring our Azure Service Bus message handlers -Registering message handlers to process the Service Bus message happens just the same as using a message pump. -Here is an example of two message handlers that are being registered during startup: - -Processing shipment messages: - -```csharp -public class ShipmentServiceBusMessageHandler : IAzureServiceBusMessageHandler -{ - private readonly ILogger _logger; - - public ShipmentServiceBusMessageHandler(ILogger logger) - { - _logger = logger; - } - - public async Task ProcessMessageAsync( - Shipment shipment, - AzureServiceBusMessageContext messageContext, - MessageCorrelationInfo correlationInfo, - CancellationToken cancellationToken) - { - _logger.LogInformation("Processing shipment {ShipmentId} for order #{OrderId}", shipment.Id, shipment.Order.Id); - } -} -``` - -Processing order messages: - -```csharp -public class OrderServiceBusMessageHandler : IAzureServiceBusMessageHandler -{ - private readonly ILogger _logger; - - public OrderServiceBusMessageHandler(ILogger logger) - { - _logger = logger; - } - - public async Task ProcessMessageAsync( - Order order, - AzureServiceBusMessageContext messageContext, - MessageCorrelationInfo correlationInfo, - CancellationToken cancellationToken) - { - _logger.LogInformation("Processing order {OrderId} for {OrderAmount} units of {OrderArticle} bought by {CustomerFirstName} {CustomerLastName}", order.Id, order.Amount, order.ArticleNumber, order.Customer. - } -} -``` - -Now that we have created our message handlers, we can declare when we should use them by registering them with our router. - -## Processing received messages through the message router -Now that everything is setup, we need to actually use the declared message handlers by routing the messages from the Azure Function into the correct message handler. - -To achieve that, we need to add message routing with the `.AddServiceBusMessageRouting` extension: - -### Isolated Azure Functions -```csharp -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -var host = new HostBuilder() - .ConfigureFunctionsWorkerDefaults(builder => - { - builder.Services.AddServiceBusMessageRouting() - .WithServiceBusMessageHandler() - .WithServiceBusMessageHandler(); - }) - .Build(); -host.Run(); -``` - -### In-Process Azure Functions -```csharp -[assembly: FunctionsStartup(typeof(Startup))] -namespace MessageProcessing -{ - public class Startup : FunctionsStartup - { - public override void Configure(IFunctionsHostBuilder builder) - { - builder.AddServiceBusMessageRouting() - .WithServiceBusMessageHandler() - .WithServiceBusMessageHandler(); - } - } -} -``` - -This extension will register an `IAzureServiceBusMessageRouter` interface allows you access to message handling with specific Service Bus operations during the message processing (like dead lettering and abandoning). - -> ⚡ It also registers an more general `IMessageRouter` you can use if the general message routing (with the message raw message body as `string` as incoming message) will suffice. - -We can now inject the message router in our Azure Function and process all messages with it. -This will determine what the matching message handler is and process it accordingly. -Upon receival of an Azure Service Bus message, the message will be either routed to one of the two previously registered message handlers. - -### Isolated Azure Functions -```csharp -using Arcus.Messaging.Abstractions.ServiceBus; -using Arcus.Messaging.AzureFunctions.ServiceBus; -using Azure.Messaging.ServiceBus; - -public class MessageProcessingFunction -{ - private readonly IAzureServiceBusMessageRouter _messageRouter; - private readonly string _jobId; - - public MessageProcessingFunction(IAzureServiceBusMessageRouter messageRouter) - { - _jobId = $"job-{Guid.NewGuid()}"; - _messageRouter = messageRouter; - } - - [Function("message-processor")] - public void Run( - [ServiceBusTrigger("%TopicName%", "%SubscriptionName%", Connection = "ServiceBusConnectionString")] byte[] messageBody, - FunctionContext executionContext) - { - ServiceBusReceivedMessage message = ConvertToServiceBusMessage(messageBody, executionContext); - - AzureServiceBusMessageContext messageContext = message.GetMessageContext(_jobId); - using (MessageCorrelationResult result = executionContext.GetCorrelationInfo()) - { - _messageRouter.ProcessMessageAsync(message, messageContext, result.CorrelationInfo, cancellationToken); - } - } - - private static ServiceBusReceivedMessage ConvertToServiceBusMessage(byte[] messageBody, FunctionContext context) - { - var applicationProperties = new Dictionary(); - if (context.BindingContext.BindingData.TryGetValue("ApplicationProperties", out object applicationPropertiesObj)) - { - var json = applicationPropertiesObj.ToString(); - applicationProperties = JsonSerializer.Deserialize>(json); - } - - var message = ServiceBusModelFactory.ServiceBusReceivedMessage( - body: BinaryData.FromBytes(messageBody), - messageId: context.BindingContext.BindingData["MessageId"]?.ToString(), - correlationId: context.BindingContext.BindingData["CorrelationId"]?.ToString(), - properties: applicationProperties); - - return message; - } -} -``` - -### In-Process Azure Functions -```csharp -using Arcus.Messaging.Abstractions.ServiceBus; -using Azure.Messaging.ServiceBus; - -public class MessageProcessingFunction -{ - private readonly IAzureServiceBusMessageRouter _messageRouter; - private readonly AzureFunctionsInProcessMessageCorrelation _messageCorrelation; - private readonly string _jobId; - - public MessageProcessingFunction( - IAzureServiceBusMessageRouter messageRouter, - AzureFunctionsInProcessMessageCorrelation messageCorrelation) - { - _jobId = $"job-{Guid.NewGuid()}"; - _messageRouter = messageRouter; - _messageCorrelation = messageCorrelation; - } - - [FunctionName("message-processor")] - public void Run( - [ServiceBusTrigger("%TopicName%", "%SubscriptionName%", Connection = "ServiceBusConnectionString")] ServiceBusReceivedMessage message, - ILogger log, - CancellationToken cancellationToken) - { - AzureServiceBusMessageContext messageContext = message.GetMessageContext(_jobId); - - // W3C message correlation (with automatic tracking of built-in Microsoft dependencies, recommended) - using (MessageCorrelationResult result = _messageCorrelation.CorrelateMessage(message)) - { - _messageRouter.ProcessMessageAsync(message, messageContext, result.CorrelationInfo, cancellationToken); - } - - // Hierarchical message correlation (without automatic tracking of built-in Microsoft dependencies)) - MessageCorrelationInfo correlationInfo = message.GetCorrelationInfo(); - - _messageRouter.ProcessMessageAsync(message, messageContext, correlationInfo, cancellationToken); - } -} -``` \ No newline at end of file diff --git a/docs/preview/02-Features/02-message-handling/04-event-hubs-azure-functions.md b/docs/preview/02-Features/02-message-handling/04-event-hubs-azure-functions.md deleted file mode 100644 index ec0b1e75..00000000 --- a/docs/preview/02-Features/02-message-handling/04-event-hubs-azure-functions.md +++ /dev/null @@ -1,241 +0,0 @@ ---- -title: "Azure EventHubs message handling for Azure Functions" -layout: default ---- - -This article describes how you can use Arcus' message handler concept with Azure Functions; allowing you to more easily port your business logic from/to Azure Functions. - -# Azure EventHubs message handling for Azure Functions -Our EventHubs message pump system provides a way to receive incoming events, but this is not needed in an Azure Functions environment. -Today, Azure Functions acts as a message receiver meaning that the function is triggered when an event is available. Azure Functions has no out-of-the-box way to provide a clean implementation for handling different types of messages that are received. If you want to do that, you'll need to write all plumbing code yourself. With Arcus.Messaging, we provide this for you so that you can focus on writing the actual business logic. - -Following terms are used: -- **Message handler**: implementation that processes the received event from an Azure EventHubs subscription. Message handlers are created by implementing the `IAzureEventHubsMessageHandler`. This message handler will be called upon when an event is available on the Azure EventHubs subscription. -- **Message router**: implementation that delegates the received Azure EventHubs event to the correct message handler. - -![Azure Functions message handling](/media/az-func-eventhubs-message-handling.png) - -We will walk you through the process of using message handlers with Azure Functions: - -## Installation -To use the following described features, install the following package: -```shell -PM > Install-Package -Name Arcus.Messaging.AzureFunctions.EventHubs -``` - -## Receive Azure EventHubs message in an Azure Function -Here's an example of how an Azure Function receives an Azure EventHubs message from a topic: - -```csharp -public class SensorReadingFunction -{ - [Function("sensor-reading")] - public async Task Run( - [EventHubTrigger("sensors", Connection = "EventHubsConnectionString")] string[] messages, - Dictionary[] propertiesArray, - FunctionContext context) - { - // Processing events... - } -} -``` - -## Declaring our Azure EventHubs message handlers -Registering message handlers to process the EventHubs events is fairly easy to do. - -> ⚡ You can use the same message handlers in an Azure Functions an a .NET Worker message pump scenario. - -Processing sensor reading updates: - -```csharp -public class SensorReadingUpdateEventHubsMessageHandler : IAzureEventHubsMessageHandler -{ - private readonly ILogger _logger; - - public SensorReadingUpdateEventHubsMessageHandler(ILogger logger) - { - _logger = logger; - } - - public async Task ProcessMessageAsync( - SensorReadingUpdate readingUpdate, - AzureEventHubsMessageContext messageContext, - MessageCorrelationInfo correlationInfo, - CancellationToken cancellationToken) - { - _logger.LogInformation("Processing sensor reading {SensorId} in room {Room}", readingUpdate.SensorId, readingUpdate.RoomName); - } -} -``` - -Processing sensor config updates: - -```csharp -public class SensorConfigUpdateMessageHandler : IAzureEventHubsMessageHandler -{ - private readonly ILogger _logger; - - public SensorConfigUpdateMessageHandler(ILogger logger) - { - _logger = logger; - } - - public async Task ProcessMessageAsync( - SensorConfigUpdate configUpdate, - AzureEventHubsMessageContext messageContext, - MessageCorrelationInfo correlationInfo, - CancellationToken cancellationToken) - { - log.LogInformation("Processing sensor config {SensorId} in room {Room}", configUpdate.SensorId, configUpdate.Room); - } -} -``` - -Now that we have created our message handlers, we can declare when we should use them by registering them with our router. - -## Processing received messages through the message router -Now that everything is setup, we need to actually use the declared message handlers by routing the events from the Azure Function into the correct message handler. - -To achieve that, we need to add message routing with the `.AddEventHubsMessageRouting` extension: - -### Isolated Azure Functions -```csharp -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -var host = new HostBuilder() - .ConfigureFunctionsWorkerDefaults(builder => - { - builder.Services.AddEventHubsMessageRouting() - .WithEventHubsMessageHandler() - .WithEventHubsMessageHandler(); - }) - .Build(); - -host.Run(); -``` - -### In-Process Azure Functions -```csharp -using Microsoft.Azure.Functions.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection; - -[assembly: FunctionsStartup(typeof(Startup))] -namespace SensorReading -{ - public class Startup : FunctionsStartup - { - public override void Configure(IFunctionsHostBuilder builder) - { - builder.AddEventHubsMessageRouting() - .WithEventHubsMessageHandler() - .WithEventHubsMessageHandler(); - } - } -} -``` - -This extension will register an `IAzureEventHubsMessageRouter` interface that allows you to interact with the registered message handlers in a easy manner. - -> ⚡ It also registers an more general `IMessageRouter` you can use if the general message routing (with the event' raw body as `string` as input) will suffice. - -We can now inject the message router in our Azure Function and process all events with it. -This will determine what the matching message handler is and process it accordingly: - -### Isolated -```csharp -using Arcus.Messaging.Abstractions.EventHubs; -using Azure.Messaging.EventHubs; - -public class SensorReadingFunction -{ - private readonly IAzureEventHubsMessageRouter _messageRouter; - - public SensorReadingFunction(IAzureEventHubsMessageRouter messageRouter) - { - _messageRouter = messageRouter; - } - - [Function("sensor-reading")] - public async Task Run( - [EventHubTrigger("sensor-reading", Connection = "EventHubsConnectionString")] string[] messages, - Dictionary[] propertiesArray, - FunctionContext executionContext) - { - _logger.LogInformation("First EventHubs triggered message: {Message}", messages[0]); - - for (var i = 0; i < messages.Length; i++) - { - string eventBody = messages[i]; - Dictionary eventProperties = propertiesArray[i]; - - EventData eventData = CreateEventData(message, eventProperties); - AzureEventHubsMessageContext messageContext = eventData.GetMessageContext("", "$Default", ""); - - using (MessageCorrelationResult result = executionContext.GetCorrelationInfo(eventProperties)) - { - await _messageRouter.RouteMessageAsync(eventData, messageContext, result.CorrelationInfo, CancellationToken.None); - } - } - } - - private static EventData CreateEventData(string eventBody, IDictionary properties) - { - var data = new EventData(eventBody); - foreach (KeyValuePair property in properties) - { - data.Properties.Add(property.Key, property.Value.ToString()); - } - - return data; - } -} -``` - -### In-Process -```csharp -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.EventHubs; -using Arcus.Messaging.Abstractions.EventHubs.MessageHandling; -using Arcus.Messaging.AzureFunctions.EventHubs; - -public class SensorReadingFunction -{ - private readonly IAzureEventHubsMessageRouter _messageRouter; - private readonly AzureFunctionsInProcessMessageCorrelation _messageCorrelation; - - public SensorReadingFunction( - IAzureEventHubsMessageRouter messageRouter, - AzureFunctionsInProcessMessageCorrelation messageCorrelation) - { - _messageRouter = messageRouter; - _messageCorrelation = messageCorrelation; - } - - [FunctionName("sensor-reading")] - public async Task Run( - [EventHubTrigger("sensors", Connection = "EventHubsConnectionString")] EventData[] events, - ILogger log, - CancellationToken cancellationToken) - { - foreach (EventData message in events) - { - log.LogInformation($"First Event Hubs triggered message: {message.MessageId}"); - - var messageContext = message.GetMessageContext("sensor-reading.servicebus.windows.net", "$Default", "sensors"); - - // W3C message correlation (with built-in Microsoft dependency tracking, recommended). - using (MessageCorrelationResult result = _messageCorrelation.CorrelateMessage(message)) - { - await _messageRouter.RouteMessageAsync(message, messageContext, result.CorrelationInfo, cancellationToken); - } - - // Hierarchical message correlation (without built-in Microsoft dependency tracking). - MessageCorrelationInfo correlationInfo = message.GetCorrelationInfo(); - await _messageRouter.RouteMessageAsync(message, messageContext, correlationInfo, cancellationToken); - } - } -} -``` - -Upon receival of an Azure EventHubs event, the event will be either routed to one of the two previously registered message handlers. diff --git a/docs/preview/02-Features/02-message-handling/05-customize-general.md b/docs/preview/02-Features/02-message-handling/05-customize-general.md deleted file mode 100644 index 3607cea9..00000000 --- a/docs/preview/02-Features/02-message-handling/05-customize-general.md +++ /dev/null @@ -1,255 +0,0 @@ ---- -title: "Customize general message handling" -layout: default ---- - -# Customize general message handling - -## Filter messages based on message context - -When registering a new message handler, one can opt-in to add a filter on the message context which filters out messages that are not needed to be processed. - -This can be useful when you are sending different message types on the same queue. Another use-case is being able to handle different versions of the same message type which have different contracts because you are migrating your application. - -Following example shows how a message handler should only process a certain message when a property's in the context is present. - -We'll use a simple message handler implementation: - -```csharp -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Pumps.Abstractions.MessagingHandling; - -public class OrderMessageHandler : IMessageHandler -{ - public async Task ProcessMessageAsync(Order order, MessageContext context, ...) - { - // Do some processing... - } -} -``` - -We would like that this handler only processed the message when the context contains `MessageType` equals `Order`. - -```csharp -using Microsoft.Extensions.DependencyInjection; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddYourMessagePump(...) - .WithMessageHandler(context => context.Properties["MessageType"].ToString() == "Order"); - } -} -``` - -> Note that the order in which the message handlers are registered is important in the message processing. -> In the example, when a message handler above this one is registered that could also handle the message (same message type) than that handler may be chosen instead of the one with the specific filter. - -## Control custom deserialization - -### Extending the message router - -By default, when using the `.AddMessageRouting`, an new `IMessageRouter` instance is registered that contains the basic message routing/handling for incoming messages. - -If you want to control the message routing or provide additional functionality, you can do this by implementing your own message router. Next to that, you can also inherit from our built-in message router and override the necessary methods of your choosing. - -Here's how you normally would register the message router: - -```csharp -public void ConfigureServices(IServiceCollection services) -{ - // Registers `IMessageRouter`. - services.AddMessageRouting(); -} -``` - -Alternatively, you can implement your own. - -```csharp -using System; -using Arcus.Messaging.Pumps.Abstractions; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -public class OrderMessageRouter : MessageRouter -{ - public OrderMessageRouter( - IServiceProvider serviceProvider, - ILogger logger) - : base(serviceProvider, logger) - { - } - - public override bool TryDeserializeToMessageFormat(string message, Type messageType, out object? result) - { - if (messageType == typeof(Order)) - { - result = JsonConvert.DeserializeObject(message); - return true; - } - else - { - result = null; - return false; - } - } -} -``` - -> Note that our built-in `MessageRouter` implements `IMessageRouter` which you can use within your application. - -When inheriting from the `MessageRouter` type, we've controlled how the incoming raw message is being deserialized. - -Based on the message type of the registered message handlers, the router determines if the incoming message can be deserialized to that type or not. - -This custom message router can be registered using the following code. The custom router will then be registered as an `IMessageRouter` instance. - -```csharp -public void ConfigureServices(IServiceCollection services) -{ - services.AddMessageRouting(serviceProvider => - { - var logger = serviceProvider.GetService>(); - return new OrderMessageRouter(serviceProvider, logger); - }); -} -``` - -### Bring your own deserialization - -You can also choose to extend the built-in message deserialization with additional deserializer to meet your needs. -This allows you to easily deserialize into different message formats or reuse existing (de)serialization capabilities that you already have without altering the message router. - -You start by implementing an `IMessageBodySerializer`. The following example shows how an expected type can be transformed to something else. -The result type (in this case `OrderBatch`) will be then be used to check if there is an `IMessageHandler` registered with that message type. - -```csharp -using Arcus.Messaging.Pumps.Abstractions.MessageHandling; - -public class OrderBatchMessageBodySerializer : IMessageBodySerializer -{ - public async Task DeserializeMessageAsync(string messageBody) - { - var serializer = new XmlSerializer(typeof(Order[])); - using (var contents = new MemoryStream(Encoding.UTF8.GetBytes(messageBody))) - { - var orders = (Order[]) serializer.Deserialize(contents); - return MessageResult.Success(new OrderBatch(orders)); - } - } -} -``` - -The registration of these message body handlers can be done just as easily as an `IMessageSerializer`: - -```csharp -using Microsoft.Extensions.DependencyInjection; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - // Register the message body serializer in the dependency container where the dependent services will be injected. - services.WithMessageHandler(..., messageBodySerializer: new OrderBatchMessageBodySerializer()); - - // Register the message body serializer in the dependency container where the dependent services are manually injected. - services.WithMessageHandler(..., messageBodySerializerImplementationFactory: serviceProvider => - { - var logger = serviceProvider.GetService>(); - return new OrderBatchMessageHandler(logger); - }); - } -} -``` - -> Note that the order in which the message handlers are registered is important in the message processing. -> In the example, when a message handler above this one is registered that could also handle the message (same message type) than that handler may be chosen instead of the one with the specific filter. - -## Filter messages based on message body - -When registering a new message handler, one can opt-in to add a filter on the incoming message body which filters out messages that are not needed to be processed. -This can be useful when you want to route messages based on the message content itself instead of the messaging context. - -Following example shows how a message handler should only process a certain message when the status is 'Sales'; meaning only `Order` for the sales division will be processed. - -```csharp -// Message to be sent: -public enum Department { Sales, Marketing, Operations } - -public class Order -{ - public string Id { get; set; } - public Department Type { get; set; } -} - -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Pumps.Abstractions.MessageHandling; - -// Message handler -public class OrderMessageHandler : IMessageHandler -{ - public async Task ProcessMessageAsync(Order order, MessageContext context, ...) - { - // Do some processing... - } -} - -using Microsoft.Extensions.DependencyInjection; - -// Message handler registration -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.WithMessageHandler((Order order) => order.Type == Department.Sales); - } -} -``` - -## Fallback message handling - -When receiving a message on the message pump and none of the registered `IMessageHandler`'s can correctly process the message, the message router normally throws and logs an exception. - -It could also happen in a scenario that's to be expected that some received messages will not be processed correctly (or you don't want them to). - -In such a scenario, you can choose to register a `IFallbackMessageHandler` in the dependency container. -This extra message handler will then process the remaining messages that can't be processed by the normal message handlers. - -Following example shows how such a message handler can be implemented: - -```csharp -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Pumps.Abstractions.MessageHandling; -using Microsoft.Extensions.Logging; - -public class WarnsUserFallbackMessageHandler : IFallbackMessageHandler -{ - private readonly ILogger _logger; - - public WarnsUserFallbackMessageHandler(ILogger logger) - { - _logger = logger; - } - - public async Task ProcessMessageAsync(string message, MessageContext context, ...) - { - _logger.LogWarning("These type of messages are expected not to be processed"); - } -} -``` - -And to register such an implementation: - -```csharp -using Microsoft.Extensions.DependencyInjection; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.WithFallbackMessageHandler(); - } -} -``` \ No newline at end of file diff --git a/docs/preview/03-Guides/migration-guide-v1.0.md b/docs/preview/03-Guides/migration-guide-v1.0.md index 416465c3..7d4c1f6d 100644 --- a/docs/preview/03-Guides/migration-guide-v1.0.md +++ b/docs/preview/03-Guides/migration-guide-v1.0.md @@ -1,4 +1,4 @@ -# Migration guide towards v1.0 +# Migrate from v0.x to v1.0 Starting from v1.0, there are some major breaking changes. To make it easier for you migrate towards this new version, we have assembled a migration guide to help you in the process. ## New Azure SDK diff --git a/docs/preview/03-Guides/migration-guide-v3.0.md b/docs/preview/03-Guides/migration-guide-v3.0.md new file mode 100644 index 00000000..5dc268ad --- /dev/null +++ b/docs/preview/03-Guides/migration-guide-v3.0.md @@ -0,0 +1,22 @@ +# Migrate from v2.x to v3.0 +Starting from v3.0, there are some major breaking changes related to the [lightweight exercise](https://github.com/arcus-azure/arcus.messaging/discussions/470) that the Messaging library gone through. This guide will make it easier for you to migrate towards this version from an older v2.x version. + +## New Service bus message handler registration +Previously, the registration of custom `IAzureServiceBusMessageHandler<>` implementations involved navigating through the many available extensions, making it rather tedious to find the right overload. + +Starting from v3.0, the registration of custom message handlers is simplified with an options model, where all message routing additions can be added. + +```diff +services.AddServiceBusQueueMessagePump(...) + .WithServiceBusMessageHandler( +- messageContextFilter: ctx => ctx.Properties["MessageType"] == "Order", +- messageBodyFiler: order => order.Type == OrderType.Registration, +- messageBodySerializer: new OrdersXmlMessageBodySerializer()); ++ options => ++ { ++ options.AddMessageContextFilter(ctx => ctx.Properties["MessageType"] == "Order") ++ .AddMessageBodyFilter(order => order.Type == OrderType.Registration) ++ .AddMessageBodySerializer(new OrdersXmlMessageBodySerializer()) ++ }); + +``` \ No newline at end of file diff --git a/src/.dockerignore b/src/.dockerignore deleted file mode 100644 index 43e8ab1e..00000000 --- a/src/.dockerignore +++ /dev/null @@ -1,10 +0,0 @@ -.dockerignore -.env -.git -.gitignore -.vs -.vscode -docker-compose.yml -docker-compose.*.yml -*/bin -*/obj diff --git a/src/Arcus.Messaging.Abstractions.EventHubs/Extensions/IServiceCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.EventHubs/Extensions/IServiceCollectionExtensions.cs index 4d842ce6..9bd016c2 100644 --- a/src/Arcus.Messaging.Abstractions.EventHubs/Extensions/IServiceCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.EventHubs/Extensions/IServiceCollectionExtensions.cs @@ -90,7 +90,9 @@ public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting serviceProvider.GetRequiredService()); +#pragma warning restore CS0618 // Type or member is obsolete return new EventHubsMessageHandlerCollection(services); } diff --git a/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/AzureEventHubsMessageRouter.cs b/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/AzureEventHubsMessageRouter.cs index 386fddb4..68943a80 100644 --- a/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/AzureEventHubsMessageRouter.cs +++ b/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/AzureEventHubsMessageRouter.cs @@ -11,6 +11,8 @@ using Serilog.Context; using ILogger = Microsoft.Extensions.Logging.ILogger; +#pragma warning disable CS0618 // Type or member is obsolete: EventHubs-related projects will be removed anyway. + namespace Arcus.Messaging.Abstractions.EventHubs.MessageHandling { /// @@ -125,7 +127,9 @@ public async Task RouteMessageAsync( /// Thrown when the , , or is null. /// /// Thrown when no message handlers or none matching message handlers are found to process the message. +#pragma warning disable CS0672 // Member overrides obsolete member: ventHubs-related projects will be removed anyway. public override async Task RouteMessageAsync( +#pragma warning restore CS0672 // Member overrides obsolete member string message, TMessageContext messageContext, MessageCorrelationInfo correlationInfo, diff --git a/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/IAzureEventHubsMessageRouter.cs b/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/IAzureEventHubsMessageRouter.cs index 7b4edcda..1461943b 100644 --- a/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/IAzureEventHubsMessageRouter.cs +++ b/src/Arcus.Messaging.Abstractions.EventHubs/MessageHandling/IAzureEventHubsMessageRouter.cs @@ -9,7 +9,9 @@ namespace Arcus.Messaging.Abstractions.EventHubs.MessageHandling /// /// Represents an that can route Azure EventHubs s. /// +#pragma warning disable CS0618 // Type or member is obsolete: EventHubs-related projects will be removed anyway. public interface IAzureEventHubsMessageRouter : IMessageRouter +#pragma warning restore CS0618 // Type or member is obsolete { /// /// Handle a new that was received by routing them through registered s diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/IServiceCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/IServiceCollectionExtensions.cs index 19000abd..ced3616e 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/IServiceCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/IServiceCollectionExtensions.cs @@ -97,7 +97,9 @@ public static ServiceBusMessageHandlerCollection AddServiceBusMessageRouting serviceProvider.GetRequiredService()); +#pragma warning restore CS0618 // Type or member is obsolete return new ServiceBusMessageHandlerCollection(services); } diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/Message.ServiceBusMessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/Message.ServiceBusMessageHandlerCollectionExtensions.cs index f55389eb..0fbdfbb1 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/Message.ServiceBusMessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/Message.ServiceBusMessageHandlerCollectionExtensions.cs @@ -20,6 +20,7 @@ public static partial class ServiceBusMessageHandlerCollectionExtensions /// The collection of handlers to use in the application. /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageBodyFilter) @@ -45,6 +46,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function that creates the message handler. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageBodyFilter, diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.Message.ServiceBusMessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.Message.ServiceBusMessageHandlerCollectionExtensions.cs index 17b37870..f1e8172c 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.Message.ServiceBusMessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.Message.ServiceBusMessageHandlerCollectionExtensions.cs @@ -21,6 +21,7 @@ public static partial class ServiceBusMessageHandlerCollectionExtensions /// The function that determines if the message handler should handle the message based on the context. /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, @@ -48,6 +49,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function that creates the message handler. /// Thrown when the , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs index 69305c23..534b072d 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs @@ -23,6 +23,7 @@ public static partial class ServiceBusMessageHandlerCollectionExtensions /// The custom to deserialize the incoming message for the . /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, @@ -51,6 +52,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe function to create a custom to deserialize the incoming message for the . /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, @@ -80,6 +82,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The that creates the message handler. /// Thrown when the , , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, @@ -110,6 +113,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The that creates the message handler. /// Thrown when the , , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs index de4b120c..65e77564 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs @@ -22,6 +22,7 @@ public static partial class ServiceBusMessageHandlerCollectionExtensions /// The function that determines if the message handler should handle the message based on the context. /// The custom to deserialize the incoming message for the . /// Thrown when the or , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, @@ -48,6 +49,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe function that determines if the message handler should handle the message based on the context. /// The function to create the custom to deserialize the incoming message for the . /// Thrown when the or , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, @@ -75,6 +77,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe custom to deserialize the incoming message for the . /// The function that creates the message handler. /// Thrown when the , , or , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, @@ -103,6 +106,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe function to create the custom to deserialize the incoming message for the . /// The function that creates the message handler. /// Thrown when the , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.ServiceBusMessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.ServiceBusMessageHandlerCollectionExtensions.cs index feb30ba5..5fbc96e4 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.ServiceBusMessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageContext.ServiceBusMessageHandlerCollectionExtensions.cs @@ -20,6 +20,7 @@ public static partial class ServiceBusMessageHandlerCollectionExtensions /// The collection of handlers to use in the application. /// The function that determines if the message handler should handle the message based on the context. /// Thrown when the or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter) @@ -47,6 +48,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe function that determines if the message handler should handle the message based on the context. /// The function that creates the message handler. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageContextFilter, diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs index 9e0d1b8a..208991fa 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.Message.ServiceBusMessageHandlerCollectionExtensions.cs @@ -22,6 +22,7 @@ public static partial class ServiceBusMessageHandlerCollectionExtensions /// The custom to deserialize the incoming message for the . /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, IMessageBodySerializer messageBodySerializer, @@ -49,6 +50,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function that creates the message handler. /// Thrown when the , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageBodyFilter, @@ -76,6 +78,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe function to create the custom to deserialize the incoming message for the . /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageBodySerializerImplementationFactory, @@ -103,6 +106,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function that creates the message handler. /// Thrown when the , , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageBodyFilter, diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs index e88fd1c8..7252e0a0 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/MessageSerializer.ServiceBusMessageHandlerCollectionExtensions.cs @@ -21,6 +21,7 @@ public static partial class ServiceBusMessageHandlerCollectionExtensions /// The collection of handlers to use in the application. /// The custom to deserialize the incoming message for the . /// Thrown when the , is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, IMessageBodySerializer messageBodySerializer) @@ -45,6 +46,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe collection of handlers to use in the application. /// The function to create the custom to deserialize the incoming message for the . /// Thrown when the , is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageBodySerializerImplementationFactory) @@ -70,6 +72,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe custom to deserialize the incoming message for the . /// The function that creates the message handler. /// Thrown when the , , is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, IMessageBodySerializer messageBodySerializer, @@ -96,6 +99,7 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandlerThe function to create the custom to deserialize the incoming message for the . /// The function that creates the message handler. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(WithServiceBusMessageHandler) + " overload with options to add additional information to the message handler registration")] public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( this ServiceBusMessageHandlerCollection handlers, Func messageBodySerializerImplementationFactory, diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/ServiceBusMessageHandlerExtensions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/ServiceBusMessageHandlerExtensions.cs index 23c54f56..18e13914 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/ServiceBusMessageHandlerExtensions.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/ServiceBusMessageHandlerExtensions.cs @@ -1,7 +1,9 @@ using System; +using Arcus.Messaging.Abstractions.MessageHandling; using Arcus.Messaging.Abstractions.ServiceBus; using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; using Azure.Messaging.ServiceBus; +using Microsoft.Extensions.Logging; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection @@ -13,8 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection public static partial class ServiceBusMessageHandlerCollectionExtensions { /// - /// Adds a implementation to process the messages from Azure Service Bus - /// resources. + /// Adds a implementation to process the messages from Azure Service Bus resources. /// /// The type of the implementation. /// The type of the message that the message handler will process. @@ -24,18 +25,28 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler where TMessage : class { - if (handlers is null) - { - throw new ArgumentNullException(nameof(handlers)); - } + return WithServiceBusMessageHandler(handlers, configureOptions: null); + } - handlers.WithMessageHandler(); - return handlers; + /// + /// Adds a implementation to process the messages from Azure Service Bus resources. + /// + /// The type of the implementation. + /// The type of the message that the message handler will process. + /// The collection of handlers to use in the application. + /// The additional set of options to configure the registration of the message handler. + /// Thrown when the is null. + public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( + this ServiceBusMessageHandlerCollection handlers, + Action> configureOptions) + where TMessageHandler : class, IAzureServiceBusMessageHandler + where TMessage : class + { + return WithServiceBusMessageHandler(handlers, provider => ActivatorUtilities.CreateInstance(provider), configureOptions); } /// - /// Adds a implementation to process the messages from Azure Service Bus - /// resources. + /// Adds a implementation to process the messages from Azure Service Bus resources. /// /// The type of the implementation. /// The type of the message that the message handler will process. @@ -47,13 +58,48 @@ public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler implementationFactory) where TMessageHandler : class, IAzureServiceBusMessageHandler where TMessage : class + { + return WithServiceBusMessageHandler(handlers, implementationFactory, configureOptions: null); + } + + /// + /// Adds a implementation to process the messages from Azure Service Bus resources. + /// + /// The type of the implementation. + /// The type of the message that the message handler will process. + /// The collection of handlers to use in the application. + /// The function that creates the message handler. + /// The additional set of options to configure the registration of the message handler. + /// Thrown when the or is null. + public static ServiceBusMessageHandlerCollection WithServiceBusMessageHandler( + this ServiceBusMessageHandlerCollection handlers, + Func implementationFactory, + Action> configureOptions) + where TMessageHandler : class, IAzureServiceBusMessageHandler + where TMessage : class { if (handlers is null) { throw new ArgumentNullException(nameof(handlers)); } - handlers.WithMessageHandler(implementationFactory); + if (implementationFactory is null) + { + throw new ArgumentNullException(nameof(implementationFactory)); + } + + var options = new ServiceBusMessageHandlerOptions(); + configureOptions?.Invoke(options); + + handlers.Services.AddTransient( + serviceProvider => MessageHandler.Create( + implementationFactory(serviceProvider), + serviceProvider.GetService>(), + handlers.JobId, + options.MessageBodyFilter, + options.MessageContextFilter, + options.MessageBodySerializerImplementationFactory?.Invoke(serviceProvider))); + return handlers; } diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/ServiceBusMessageHandlerOptions.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/ServiceBusMessageHandlerOptions.cs new file mode 100644 index 00000000..77f99283 --- /dev/null +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/Extensions/ServiceBusMessageHandlerOptions.cs @@ -0,0 +1,79 @@ +using System; +using Arcus.Messaging.Abstractions.MessageHandling; +using Arcus.Messaging.Abstractions.ServiceBus; +using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; +using Azure.Messaging.ServiceBus; + +// ReSharper disable once CheckNamespace +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Represents the available options when registering an . + /// + /// The custom message type to handler. + public class ServiceBusMessageHandlerOptions + { + internal Func MessageBodySerializerImplementationFactory { get; private set; } + internal Func MessageBodyFilter { get; private set; } + internal Func MessageContextFilter { get; private set; } + + /// + /// Adds a custom serializer instance that deserializes the incoming . + /// + /// Thrown when the is null. + public ServiceBusMessageHandlerOptions AddMessageBodySerializer(IMessageBodySerializer serializer) + { + if (serializer is null) + { + throw new ArgumentNullException(nameof(serializer)); + } + + return AddMessageBodySerializer(_ => serializer); + } + + /// + /// Adds a custom serializer instance that deserializes the incoming . + /// + /// Thrown when the is null. + public ServiceBusMessageHandlerOptions AddMessageBodySerializer( + Func implementationFactory) + { + if (implementationFactory is null) + { + throw new ArgumentNullException(nameof(implementationFactory)); + } + + MessageBodySerializerImplementationFactory = implementationFactory; + return this; + } + + /// + /// Adds a custom to only select a subset of messages, based on its body, that the registered message handler can handle. + /// + public ServiceBusMessageHandlerOptions AddMessageBodyFilter(Func bodyFilter) + { + if (bodyFilter is null) + { + throw new ArgumentNullException(nameof(bodyFilter)); + } + + MessageBodyFilter = bodyFilter; + return this; + } + + /// + /// Adds a custom to only select a subset of messages, based on its context, that the registered message handler can handle. + /// + public ServiceBusMessageHandlerOptions AddMessageContextFilter( + Func contextFilter) + { + if (contextFilter is null) + { + throw new ArgumentNullException(nameof(contextFilter)); + } + + MessageContextFilter = contextFilter; + return this; + } + } +} \ No newline at end of file diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/AzureServiceBusMessageRouter.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/AzureServiceBusMessageRouter.cs index bbd65e5e..fd00290a 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/AzureServiceBusMessageRouter.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/AzureServiceBusMessageRouter.cs @@ -29,8 +29,9 @@ public class AzureServiceBusMessageRouter : MessageRouter, IAzureServiceBusMessa /// The logger instance to write diagnostic trace messages during the routing of the message. /// Thrown when the is null. public AzureServiceBusMessageRouter(IServiceProvider serviceProvider, AzureServiceBusMessageRouterOptions options, ILogger logger) - : this(serviceProvider, options, (ILogger) logger) + : base(serviceProvider, options, (ILogger) logger) { + ServiceBusOptions = options; } /// @@ -39,6 +40,7 @@ public AzureServiceBusMessageRouter(IServiceProvider serviceProvider, AzureServi /// The service provider instance to retrieve all the instances. /// The consumer-configurable options to change the behavior of the router. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] public AzureServiceBusMessageRouter(IServiceProvider serviceProvider, AzureServiceBusMessageRouterOptions options) : this(serviceProvider, options, NullLogger.Instance) { @@ -50,6 +52,7 @@ public AzureServiceBusMessageRouter(IServiceProvider serviceProvider, AzureServi /// The service provider instance to retrieve all the instances. /// The logger instance to write diagnostic trace messages during the routing of the message. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] public AzureServiceBusMessageRouter(IServiceProvider serviceProvider, ILogger logger) : this(serviceProvider, new AzureServiceBusMessageRouterOptions(), (ILogger) logger) { @@ -60,6 +63,7 @@ public AzureServiceBusMessageRouter(IServiceProvider serviceProvider, ILogger /// The service provider instance to retrieve all the instances. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] public AzureServiceBusMessageRouter(IServiceProvider serviceProvider) : this(serviceProvider, new AzureServiceBusMessageRouterOptions(), NullLogger.Instance) { @@ -71,6 +75,7 @@ public AzureServiceBusMessageRouter(IServiceProvider serviceProvider) /// The service provider instance to retrieve all the instances. /// The logger instance to write diagnostic trace messages during the routing of the message. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] protected AzureServiceBusMessageRouter(IServiceProvider serviceProvider, ILogger logger) : this(serviceProvider, new AzureServiceBusMessageRouterOptions(), logger) { @@ -83,6 +88,7 @@ protected AzureServiceBusMessageRouter(IServiceProvider serviceProvider, ILogger /// The consumer-configurable options to change the behavior of the router. /// The logger instance to write diagnostic trace messages during the routing of the message. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] protected AzureServiceBusMessageRouter(IServiceProvider serviceProvider, AzureServiceBusMessageRouterOptions options, ILogger logger) : base(serviceProvider, options, logger ?? NullLogger.Instance) { @@ -106,6 +112,7 @@ protected AzureServiceBusMessageRouter(IServiceProvider serviceProvider, AzureSe /// Thrown when the , , or is null. /// /// Thrown when no message handlers or none matching message handlers are found to process the message. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] public override async Task RouteMessageAsync( string message, TMessageContext messageContext, @@ -315,7 +322,9 @@ private async Task TryRouteMessageWithPotentialFallback return MessageProcessingResult.Failure(message.MessageId, CannotFindMatchedHandler, "Failed to process message in pump as no message handler was matched against the message and no fallback message handlers were configured"); } +#pragma warning disable CS0618 // Type or member is obsolete: general message routing will be removed in v3.0. bool isProcessedByGeneralFallback = await TryFallbackProcessMessageAsync(messageBody, messageContext, correlationInfo, cancellationToken); +#pragma warning restore CS0618 // Type or member is obsolete if (isProcessedByGeneralFallback) { return MessageProcessingResult.Success(message.MessageId); diff --git a/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/IAzureServiceBusMessageRouter.cs b/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/IAzureServiceBusMessageRouter.cs index af4cd564..eb8a472c 100644 --- a/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/IAzureServiceBusMessageRouter.cs +++ b/src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/IAzureServiceBusMessageRouter.cs @@ -9,7 +9,9 @@ namespace Arcus.Messaging.Abstractions.ServiceBus.MessageHandling /// /// Represents an that can route Azure Service Bus s. /// +#pragma warning disable CS0618 // Type or member is obsolete: general message router interface will be removed in v3.0. public interface IAzureServiceBusMessageRouter : IMessageRouter +#pragma warning restore CS0618 // Type or member is obsolete { /// /// Handle a new that was received by routing them through registered s diff --git a/src/Arcus.Messaging.Abstractions/Arcus.Messaging.Abstractions.csproj b/src/Arcus.Messaging.Abstractions/Arcus.Messaging.Abstractions.csproj index d9e5f949..2cefbcae 100644 --- a/src/Arcus.Messaging.Abstractions/Arcus.Messaging.Abstractions.csproj +++ b/src/Arcus.Messaging.Abstractions/Arcus.Messaging.Abstractions.csproj @@ -27,9 +27,11 @@ + - + + \ No newline at end of file diff --git a/src/Arcus.Messaging.Abstractions/Extensions/IServiceCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions/Extensions/IServiceCollectionExtensions.cs index b1801e35..5e6db4e2 100644 --- a/src/Arcus.Messaging.Abstractions/Extensions/IServiceCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions/Extensions/IServiceCollectionExtensions.cs @@ -18,6 +18,7 @@ public static class IServiceCollectionExtensions /// /// The collection of services to add the router to. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] public static MessageHandlerCollection AddMessageRouting(this IServiceCollection services) { MessageHandlerCollection collection = AddMessageRouting(services, configureOptions: null); @@ -30,6 +31,7 @@ public static MessageHandlerCollection AddMessageRouting(this IServiceCollection /// The collection of services to add the router to. /// The consumer-configurable options to change the behavior of the router. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] public static MessageHandlerCollection AddMessageRouting(this IServiceCollection services, Action configureOptions) { MessageHandlerCollection collection = AddMessageRouting(services, serviceProvider => @@ -51,6 +53,7 @@ public static MessageHandlerCollection AddMessageRouting(this IServiceCollection /// The collection of services to add the router to. /// The function to create the . /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] public static MessageHandlerCollection AddMessageRouting( this IServiceCollection services, Func implementationFactory) diff --git a/src/Arcus.Messaging.Abstractions/Extensions/MessageBody.MessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions/Extensions/MessageBody.MessageHandlerCollectionExtensions.cs index a6a6e06f..73156ed2 100644 --- a/src/Arcus.Messaging.Abstractions/Extensions/MessageBody.MessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions/Extensions/MessageBody.MessageHandlerCollectionExtensions.cs @@ -20,6 +20,7 @@ public static partial class MessageHandlerCollectionExtensions /// The collection of services to use in the application. /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageBodyFilter) @@ -60,6 +61,7 @@ public static MessageHandlerCollection WithMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function that creates the service. /// Thrown when the , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageBodyFilter, diff --git a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageBody.IServiceCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageBody.IServiceCollectionExtensions.cs index 7e87a416..27c7b493 100644 --- a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageBody.IServiceCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageBody.IServiceCollectionExtensions.cs @@ -1,7 +1,6 @@ using System; using Arcus.Messaging.Abstractions; using Arcus.Messaging.Abstractions.MessageHandling; -using GuardNet; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection @@ -23,6 +22,7 @@ public static partial class MessageHandlerCollectionExtensions /// The filter to restrict the message processing based on the incoming message body. /// The function that creates the service. /// Thrown when the , , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -44,6 +44,7 @@ public static MessageHandlerCollection WithMessageHandlerThe function that determines if the message handler should handle the message based on the context. /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, diff --git a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageHandlerCollectionExtensions.cs index db909c2b..e3c11893 100644 --- a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageHandlerCollectionExtensions.cs @@ -20,6 +20,7 @@ public static partial class MessageHandlerCollectionExtensions /// The collection of services to use in the application. /// The function that determines if the message handler should handle the message based on the context. /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter) @@ -39,6 +40,7 @@ public static MessageHandlerCollection WithMessageHandlerThe function that determines if the message handler should handle the message based on the context. /// The function that creates the service. /// Thrown when the , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -70,7 +72,7 @@ public static MessageHandlerCollection WithMessageHandler ActivatorUtilities.CreateInstance(serviceProvider)); } - /// + /// /// Adds a implementation to process the messages from an Azure Service Bus. /// resources. /// diff --git a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageBody.IServiceCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageBody.IServiceCollectionExtensions.cs index 8f45e03e..891285dc 100644 --- a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageBody.IServiceCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageBody.IServiceCollectionExtensions.cs @@ -22,6 +22,7 @@ public static partial class MessageHandlerCollectionExtensions /// The filter to restrict the message processing based on the incoming message body. /// The custom to deserialize the incoming message for the . /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -44,6 +45,7 @@ public static MessageHandlerCollection WithMessageHandlerThe function to create an custom to deserialize the incoming message for the . /// The filter to restrict the message processing based on the incoming message body. /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -117,6 +119,7 @@ public static MessageHandlerCollection WithMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function that creates the service. /// Thrown when the , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -142,6 +145,7 @@ public static MessageHandlerCollection WithMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function that creates the service. /// Thrown when the , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, diff --git a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageHandlerCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageHandlerCollectionExtensions.cs index 53a97d30..ddb677e2 100644 --- a/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageHandlerCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions/Extensions/MessageContext.MessageSerializer.MessageHandlerCollectionExtensions.cs @@ -20,6 +20,7 @@ public static partial class MessageHandlerCollectionExtensions /// The collection of services to use in the application. /// The function that determines if the message handler should handle the message based on the context. /// The custom that deserializes the incoming message for the . + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -39,6 +40,7 @@ public static MessageHandlerCollection WithMessageHandlerThe collection of services to use in the application. /// The function that determines if the message handler should handle the message based on the context. /// The custom that deserializes the incoming message for the . + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -59,6 +61,7 @@ public static MessageHandlerCollection WithMessageHandlerThe function that determines if the message handler should handle the message based on the context. /// The custom that deserializes the incoming message for the . /// The function that creates the service. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -81,6 +84,7 @@ public static MessageHandlerCollection WithMessageHandlerThe function that determines if the message handler should handle the message based on the context. /// The custom that deserializes the incoming message for the . /// The function that creates the service. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageContextFilter, @@ -91,8 +95,8 @@ public static MessageHandlerCollection WithMessageHandler( services, - messageContextFilter, - messageBodySerializerImplementationFactory, + messageContextFilter, + messageBodySerializerImplementationFactory, messageHandlerImplementationFactory); } @@ -210,10 +214,10 @@ public static MessageHandlerCollection WithMessageHandlerThe type of the message that the message handler will process. /// The collection of collection to use in the application. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler(this MessageHandlerCollection collection) where TMessageHandler : class, IMessageHandler where TMessage : class @@ -36,6 +37,7 @@ public static MessageHandlerCollection WithMessageHandlerThe collection of collection to use in the application. /// The function that creates the service. /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection collection, Func implementationFactory) @@ -55,7 +57,7 @@ public static MessageHandlerCollection WithMessageHandlerThe collection of collection to use in the application. /// Thrown when the is null. public static MessageHandlerCollection WithMessageHandler(this MessageHandlerCollection collection) - where TMessageHandler : class, IMessageHandler + where TMessageHandler : class, IMessageHandler where TMessage : class where TMessageContext : MessageContext { @@ -76,7 +78,7 @@ public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection collection, Func implementationFactory) - where TMessageHandler : class, IMessageHandler + where TMessageHandler : class, IMessageHandler where TMessage : class where TMessageContext : MessageContext { @@ -100,6 +102,7 @@ public static MessageHandlerCollection WithMessageHandlerThe type of the fallback message handler. /// The collection to add the fallback message handler to. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithFallbackMessageHandler(this MessageHandlerCollection collection) where TMessageHandler : IFallbackMessageHandler { @@ -113,6 +116,7 @@ public static MessageHandlerCollection WithFallbackMessageHandlerThe type of the message context. /// The collection to add the fallback message handler to. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithFallbackMessageHandler(this MessageHandlerCollection collection) where TMessageHandler : IFallbackMessageHandler where TMessageContext : MessageContext @@ -127,6 +131,7 @@ public static MessageHandlerCollection WithFallbackMessageHandlerThe collection to add the fallback message handler to. /// The function to create the fallback message handler. /// Thrown when the or the is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithFallbackMessageHandler( this MessageHandlerCollection collection, Func createImplementation) @@ -154,10 +159,11 @@ public static MessageHandlerCollection WithFallbackMessageHandlerThe collection to add the fallback message handler to. /// The function to create the fallback message handler. /// Thrown when the or the is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithFallbackMessageHandler( this MessageHandlerCollection collection, Func createImplementation) - where TMessageHandler : IFallbackMessageHandler + where TMessageHandler : IFallbackMessageHandler where TMessageContext : MessageContext { if (collection is null) diff --git a/src/Arcus.Messaging.Abstractions/Extensions/MessageSerializer.MessageBody.IServiceCollectionExtensions.cs b/src/Arcus.Messaging.Abstractions/Extensions/MessageSerializer.MessageBody.IServiceCollectionExtensions.cs index 10083291..bfd14756 100644 --- a/src/Arcus.Messaging.Abstractions/Extensions/MessageSerializer.MessageBody.IServiceCollectionExtensions.cs +++ b/src/Arcus.Messaging.Abstractions/Extensions/MessageSerializer.MessageBody.IServiceCollectionExtensions.cs @@ -21,6 +21,7 @@ public static partial class MessageHandlerCollectionExtensions /// The filter to restrict the message processing based on the incoming message body. /// The custom to deserialize the incoming message for the . /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, IMessageBodySerializer messageBodySerializer, @@ -41,6 +42,7 @@ public static MessageHandlerCollection WithMessageHandlerThe filter to restrict the message processing based on the incoming message body. /// The function to create an custom to deserialize the incoming message for the . /// Thrown when the or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageBodySerializerImplementationFactory, @@ -108,6 +110,7 @@ public static MessageHandlerCollection WithMessageHandlerThe function that creates the service. /// The custom to deserialize the incoming message for the . /// Thrown when the , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, IMessageBodySerializer messageBodySerializer, @@ -131,6 +134,7 @@ public static MessageHandlerCollection WithMessageHandlerThe function that creates the service. /// The function to create an custom to deserialize the incoming message for the . /// Thrown when the , , or is null. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageBodySerializerImplementationFactory, @@ -218,10 +222,10 @@ public static MessageHandlerCollection WithMessageHandlerThe type of the message that the message handler will process. /// The collection of services to use in the application. /// The custom to deserialize the incoming message for the . + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, IMessageBodySerializer messageBodySerializer) @@ -56,6 +57,7 @@ public static MessageHandlerCollection WithMessageHandlerThe collection of services to use in the application. /// The function to create the custom that deserializes the incoming message for the . /// The function that creates the service. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, IMessageBodySerializer messageBodySerializer, @@ -91,7 +93,7 @@ public static MessageHandlerCollection WithMessageHandler( services, - messageBodySerializerImplementationFactory: _ => messageBodySerializer, + messageBodySerializerImplementationFactory: _ => messageBodySerializer, messageHandlerImplementationFactory: implementationFactory); } @@ -103,6 +105,7 @@ public static MessageHandlerCollection WithMessageHandlerThe type of the message that the message handler will process. /// The collection of services to use in the application. /// The function to create an custom to deserialize the incoming message for the . + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageBodySerializerImplementationFactory) @@ -130,7 +133,7 @@ public static MessageHandlerCollection WithMessageHandler( services, - messageBodySerializerImplementationFactory, + messageBodySerializerImplementationFactory, serviceProvider => ActivatorUtilities.CreateInstance(serviceProvider)); } @@ -142,6 +145,7 @@ public static MessageHandlerCollection WithMessageHandlerThe collection of services to use in the application. /// The function to create the custom that deserializes the incoming message for the . /// The function that creates the service. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public static MessageHandlerCollection WithMessageHandler( this MessageHandlerCollection services, Func messageBodySerializerImplementationFactory, diff --git a/src/Arcus.Messaging.Abstractions/MessageContext.cs b/src/Arcus.Messaging.Abstractions/MessageContext.cs index 2d29ff53..b6478fd7 100644 --- a/src/Arcus.Messaging.Abstractions/MessageContext.cs +++ b/src/Arcus.Messaging.Abstractions/MessageContext.cs @@ -15,6 +15,7 @@ public class MessageContext /// The contextual properties provided on the message. /// Thrown when the is blank. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as only job-linked message contexts are supported from now on")] public MessageContext(string messageId, IDictionary properties) { if (string.IsNullOrWhiteSpace(messageId)) diff --git a/src/Arcus.Messaging.Abstractions/MessageHandling/IFallbackMessageHandler.cs b/src/Arcus.Messaging.Abstractions/MessageHandling/IFallbackMessageHandler.cs index b06e3859..036d7096 100644 --- a/src/Arcus.Messaging.Abstractions/MessageHandling/IFallbackMessageHandler.cs +++ b/src/Arcus.Messaging.Abstractions/MessageHandling/IFallbackMessageHandler.cs @@ -33,6 +33,7 @@ Task ProcessMessageAsync( /// /// Fallback version of the to have a safety net when no message handlers able to process the message. /// + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public interface IFallbackMessageHandler : IMessageHandler { } @@ -40,6 +41,7 @@ public interface IFallbackMessageHandler : IMessageHandler /// Fallback version of the to have a safety net when no message handlers able to process the message. /// + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public interface IFallbackMessageHandler : IFallbackMessageHandler { } diff --git a/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageHandler.cs b/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageHandler.cs index fcf6fa30..f59dc1ad 100644 --- a/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageHandler.cs +++ b/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageHandler.cs @@ -31,6 +31,7 @@ Task ProcessMessageAsync( /// Represents a handler for a specific in a /// during the processing of the message pump or router. /// + [Obsolete("Will be removed in v3.0 as only concrete implementations of message handling will be supported from now on")] public interface IMessageHandler : IMessageHandler { } diff --git a/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageRouter.cs b/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageRouter.cs index 778e2567..22de6a4d 100644 --- a/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageRouter.cs +++ b/src/Arcus.Messaging.Abstractions/MessageHandling/IMessageRouter.cs @@ -7,11 +7,12 @@ namespace Arcus.Messaging.Abstractions.MessageHandling /// /// Represents how incoming messages can be routed through registered instances. /// + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] public interface IMessageRouter { /// /// Handle a new that was received by routing them through registered s - /// and optionally through an registered if none of the message handlers were able to process the . + /// and optionally through a registered if none of the message handlers were able to process the . /// /// The message that was received. /// The context providing more information concerning the processing. @@ -21,6 +22,7 @@ public interface IMessageRouter /// Thrown when the , , or is null. /// /// Thrown when no message handlers or none matching message handlers are found to process the message. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] Task RouteMessageAsync( string message, TMessageContext messageContext, diff --git a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationFormat.cs b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationFormat.cs index 1bd2b003..f984b4db 100644 --- a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationFormat.cs +++ b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationFormat.cs @@ -1,4 +1,8 @@ -namespace Arcus.Messaging.Abstractions.MessageHandling +using System; + +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. + +namespace Arcus.Messaging.Abstractions.MessageHandling { /// /// Represents the message correlation format of the received message. @@ -13,6 +17,7 @@ public enum MessageCorrelationFormat /// /// Uses the hierarchical message correlation system with Root-Id and Request-Id to represent parent-child relationship. /// + [Obsolete("Hierarchical correlation will be removed in v3.0")] Hierarchical } } \ No newline at end of file diff --git a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationOptions.cs b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationOptions.cs index b05d8c3f..19de8e4f 100644 --- a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationOptions.cs +++ b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationOptions.cs @@ -1,5 +1,7 @@ using System; +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. + namespace Arcus.Messaging.Abstractions.MessageHandling { /// @@ -7,6 +9,7 @@ namespace Arcus.Messaging.Abstractions.MessageHandling /// public class MessageCorrelationOptions { + [Obsolete("Will be removed in v3.0")] private string _transactionIdPropertyName = PropertyNames.TransactionId, _operationParentIdPropertyName = PropertyNames.OperationParentId; @@ -22,6 +25,7 @@ public class MessageCorrelationOptions /// Only used when the is set to . /// /// Thrown when the is blank. + [Obsolete("Will be removed in v3.0 as the property name is only used in the deprecated 'Hierarchical' correlation format")] public string TransactionIdPropertyName { get => _transactionIdPropertyName; @@ -43,6 +47,7 @@ public string TransactionIdPropertyName /// Only used when the is set to . /// /// Thrown when the is blank. + [Obsolete("Will be removed in v3.0 as the property name is only used in the deprecated 'Hierarchical' correlation format")] public string OperationParentIdPropertyName { get => _operationParentIdPropertyName; diff --git a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageHandler.cs b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageHandler.cs index b0487cca..3063b7e9 100644 --- a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageHandler.cs +++ b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageHandler.cs @@ -89,7 +89,7 @@ public static IEnumerable SubtractFrom(IServiceProvider serviceP /// The logger instance to write diagnostic messages during the message handler interaction. /// Thrown when the is null. /// Thrown when the is blank. - internal static MessageHandler Create( + public static MessageHandler Create( IMessageHandler messageHandler, ILogger logger, string jobId, diff --git a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageRouter.cs b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageRouter.cs index c27c15a1..ac6c2622 100644 --- a/src/Arcus.Messaging.Abstractions/MessageHandling/MessageRouter.cs +++ b/src/Arcus.Messaging.Abstractions/MessageHandling/MessageRouter.cs @@ -1,15 +1,14 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; using Arcus.Messaging.Abstractions.Telemetry; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; using Serilog.Context; namespace Arcus.Messaging.Abstractions.MessageHandling @@ -17,8 +16,12 @@ namespace Arcus.Messaging.Abstractions.MessageHandling /// /// Represents how incoming messages gets routed through registered instances. /// +#pragma warning disable CS0618 // Type or member is obsolete: deprecated interface will be removed in v3.0. public class MessageRouter : IMessageRouter +#pragma warning restore CS0618 // Type or member is obsolete { + private readonly JsonSerializerOptions _jsonOptions; + /// /// Initializes a new instance of the class. /// @@ -26,6 +29,7 @@ public class MessageRouter : IMessageRouter /// The consumer-configurable options to change the behavior of the router. /// The logger instance to write diagnostic trace messages during the routing of the message. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] public MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions options, ILogger logger) : this(serviceProvider, options, (ILogger) logger) { @@ -37,6 +41,7 @@ public MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions opti /// The service provider instance to retrieve all the instances. /// The consumer-configurable options to change the behavior of the router. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] public MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions options) : this(serviceProvider, options, NullLogger.Instance) { @@ -48,6 +53,7 @@ public MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions opti /// The service provider instance to retrieve all the instances. /// The logger instance to write diagnostic trace messages during the routing of the message. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] public MessageRouter(IServiceProvider serviceProvider, ILogger logger) : this(serviceProvider, new MessageRouterOptions(), (ILogger) logger) { @@ -58,6 +64,7 @@ public MessageRouter(IServiceProvider serviceProvider, ILogger lo /// /// The service provider instance to retrieve all the instances. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] public MessageRouter(IServiceProvider serviceProvider) : this(serviceProvider, new MessageRouterOptions(), NullLogger.Instance) { @@ -69,6 +76,7 @@ public MessageRouter(IServiceProvider serviceProvider) /// The service provider instance to retrieve all the instances. /// The logger instance to write diagnostic trace messages during the routing of the message. /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 for simplified message router initialization")] protected MessageRouter(IServiceProvider serviceProvider, ILogger logger) : this(serviceProvider, new MessageRouterOptions(), logger) { @@ -86,6 +94,25 @@ protected MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions o ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); Options = options ?? new MessageRouterOptions(); Logger = logger ?? NullLogger.Instance; + + _jsonOptions = CreateJsonSerializerOptions(Options.Deserialization, Logger); + } + + private static JsonSerializerOptions CreateJsonSerializerOptions(MessageDeserializationOptions deserializationOptions, ILogger logger) + { + var jsonOptions = new JsonSerializerOptions + { + UnmappedMemberHandling = deserializationOptions?.AdditionalMembers switch + { + null => JsonUnmappedMemberHandling.Disallow, + AdditionalMemberHandling.Error => JsonUnmappedMemberHandling.Disallow, + AdditionalMemberHandling.Ignore => JsonUnmappedMemberHandling.Skip, + _ => JsonUnmappedMemberHandling.Disallow + } + }; + + logger.LogTrace("JSON deserialization uses '{UnmappedMemberHandling}' result when encountering additional members", jsonOptions.UnmappedMemberHandling); + return jsonOptions; } /// @@ -118,6 +145,7 @@ protected MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions o /// /// [true] if the router was able to process the message through one of the registered s; [false] otherwise. /// + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] protected async Task RouteMessageWithoutFallbackAsync( string message, TMessageContext messageContext, @@ -165,6 +193,7 @@ protected async Task RouteMessageWithoutFallbackAsync( /// Thrown when the , , or is null. /// /// Thrown when no message handlers or none matching message handlers are found to process the message. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] public virtual async Task RouteMessageAsync( string message, TMessageContext messageContext, @@ -212,6 +241,7 @@ public virtual async Task RouteMessageAsync( /// Thrown when the , , or is null. /// /// Thrown when no message handlers or none matching message handlers are found to process the message. + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] protected async Task RouteMessageAsync( IServiceProvider serviceProvider, string message, @@ -365,6 +395,7 @@ private async Task DeserializeMessageAsync(MessageHandler handler /// /// [true] if the received was handled by the registered ; [false] otherwise. /// + [Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")] protected async Task TryFallbackProcessMessageAsync( string message, TMessageContext messageContext, @@ -480,67 +511,22 @@ protected virtual bool TryDeserializeToMessageFormat(string message, Type messag } Logger.LogTrace("Try to JSON deserialize incoming message to message type '{MessageType}'...", messageType.Name); - - var success = true; - JsonSerializer jsonSerializer = CreateJsonSerializer(); - EventHandler eventHandler = (sender, args) => - { - success = false; - Logger.LogTrace(args.ErrorContext.Error, "Incoming message failed to be JSON deserialized to message type '{MessageType}' at {Path}", messageType.Name, args.ErrorContext.Path); - args.ErrorContext.Handled = true; - }; - jsonSerializer.Error += eventHandler; - try { - var value = JToken.Parse(message).ToObject(messageType, jsonSerializer); - if (success) + result = JsonSerializer.Deserialize(message, messageType, _jsonOptions); + if (result != null) { Logger.LogTrace("Incoming message was successfully JSON deserialized to message type '{MessageType}'", messageType.Name); - - result = value; return true; } } - catch (Exception exception) - { - Logger.LogError(exception, "Incoming message failed to be JSON deserialized to message type '{MessageType}' due to an exception", messageType.Name); - } - finally + catch (JsonException exception) { - jsonSerializer.Error -= eventHandler; + Logger.LogTrace(exception, "Incoming message failed to be JSON deserialized to message type '{MessageType}' due to an exception", messageType.Name); } result = null; return false; } - - private JsonSerializer CreateJsonSerializer() - { - var jsonSerializer = new JsonSerializer(); - - if (Options.Deserialization is null) - { - jsonSerializer.MissingMemberHandling = MissingMemberHandling.Error; - } - else - { - switch (Options.Deserialization.AdditionalMembers) - { - case AdditionalMemberHandling.Error: - jsonSerializer.MissingMemberHandling = MissingMemberHandling.Error; - break; - case AdditionalMemberHandling.Ignore: - jsonSerializer.MissingMemberHandling = MissingMemberHandling.Ignore; - break; - default: - jsonSerializer.MissingMemberHandling = MissingMemberHandling.Error; - break; - } - } - - Logger.LogTrace($"JSON deserialization uses '{jsonSerializer.MissingMemberHandling}' result when encountering additional members"); - return jsonSerializer; - } } } diff --git a/src/Arcus.Messaging.Abstractions/PropertyNames.cs b/src/Arcus.Messaging.Abstractions/PropertyNames.cs index d2414575..856fd7a4 100644 --- a/src/Arcus.Messaging.Abstractions/PropertyNames.cs +++ b/src/Arcus.Messaging.Abstractions/PropertyNames.cs @@ -1,4 +1,8 @@ -namespace Arcus.Messaging.Abstractions +using System; + +#pragma warning disable S1133 // Deprecated functionality will be removed in v3.0. + +namespace Arcus.Messaging.Abstractions { /// /// Represents general property names within contextual information of processing messages. @@ -8,18 +12,20 @@ public static class PropertyNames /// /// Gets the default context property name to get the operation ID of the parent operation. /// + [Obsolete("Will be removed in v3.0 as the property name is only used in the deprecated 'Hierarchical' correlation format")] public const string OperationParentId = "Operation-Parent-Id"; /// /// Gets the context property name to get the correlation transaction ID. /// + [Obsolete("Will be removed in v3.0 as the property name is only used in the deprecated 'Hierarchical' correlation format")] public const string TransactionId = "Transaction-Id"; - + /// /// Gets the context property name to get the encoding that was used on the message. /// public const string Encoding = "Message-Encoding"; - + /// /// Gets the context property to get the content type of the message. /// diff --git a/src/Arcus.Messaging.AzureFunctions.EventHubs/Arcus.Messaging.AzureFunctions.EventHubs.csproj b/src/Arcus.Messaging.AzureFunctions.EventHubs/Arcus.Messaging.AzureFunctions.EventHubs.csproj deleted file mode 100644 index a9705dcf..00000000 --- a/src/Arcus.Messaging.AzureFunctions.EventHubs/Arcus.Messaging.AzureFunctions.EventHubs.csproj +++ /dev/null @@ -1,43 +0,0 @@ - - - - net8.0;net6.0 - latest - Arcus - Arcus - Arcus.Messaging - Provides Azure EventHubs message handling/routing for Azure Functions. - Copyright (c) Arcus - https://messaging.arcus-azure.net/ - https://github.com/arcus-azure/arcus.messaging - LICENSE - icon.png - README.md - Git - Azure;Messaging;EventHubs;AzureFunctions - true - true - true - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Arcus.Messaging.AzureFunctions.EventHubs/AzureFunctionsInProcessMessageCorrelation.cs b/src/Arcus.Messaging.AzureFunctions.EventHubs/AzureFunctionsInProcessMessageCorrelation.cs deleted file mode 100644 index 3e567c41..00000000 --- a/src/Arcus.Messaging.AzureFunctions.EventHubs/AzureFunctionsInProcessMessageCorrelation.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Arcus.Messaging.Abstractions; -using Azure.Messaging.EventHubs; -using Microsoft.ApplicationInsights; - -namespace Arcus.Messaging.AzureFunctions.EventHubs -{ - /// - /// Represents the W3C message correlation for incoming Azure EventHubs messages in in-process Azure Functions environments. - /// - public class AzureFunctionsInProcessMessageCorrelation - { - private readonly TelemetryClient _telemetryClient; - - /// - /// Initializes a new instance of the class. - /// - /// The Microsoft telemetry client to automatically track outgoing built-in Microsoft dependencies. - /// Thrown when the is null. - public AzureFunctionsInProcessMessageCorrelation(TelemetryClient client) - { - _telemetryClient = client ?? throw new ArgumentNullException(nameof(client)); - } - - /// - /// Correlate the incoming Azure EventHubs message using the W3C message correlation. - /// - /// The incoming Azure EventHubs message. - /// The disposable message correlation telemetry request scope. - /// Thrown when the is null. - public MessageCorrelationResult CorrelateMessage(EventData message) - { - if (message is null) - { - throw new ArgumentNullException(nameof(message)); - } - - (string transactionId, string operationParentId) = message.Properties.GetTraceParent(); - return MessageCorrelationResult.Create(_telemetryClient, transactionId, operationParentId); - } - } -} diff --git a/src/Arcus.Messaging.AzureFunctions.EventHubs/Extensions/FunctionContextExtensions.cs b/src/Arcus.Messaging.AzureFunctions.EventHubs/Extensions/FunctionContextExtensions.cs deleted file mode 100644 index 2d35c1ee..00000000 --- a/src/Arcus.Messaging.AzureFunctions.EventHubs/Extensions/FunctionContextExtensions.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json; -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.MessageHandling; -using Microsoft.ApplicationInsights; -using Microsoft.Extensions.DependencyInjection; - -// ReSharper disable once CheckNamespace -namespace Microsoft.Azure.Functions.Worker -{ - /// - /// Extensions on the related to message correlation. - /// - public static class FunctionContextExtensions - { - /// - /// Determine W3C message correlation from incoming execution . - /// - /// The execution context of the isolated Azure Functions. - /// The passed along application properties for the received event on Azure EventHubs. - /// An disposable message correlation that acts as a request scope for the remaining execution of the function. - /// Thrown when the or the is null. - /// - /// Thrown when no could be found in the registered services or when no message correlation format could be determined. - /// - public static MessageCorrelationResult GetCorrelationInfo( - this FunctionContext context, - Dictionary applicationProperties) - { - return GetCorrelationInfo(context, applicationProperties, MessageCorrelationFormat.W3C); - } - - /// - /// Determine message correlation from incoming execution . - /// - /// The execution context of the isolated Azure Functions. - /// The passed along application properties for the received event on Azure EventHubs. - /// The format of the message correlation that should be used. - /// An disposable message correlation that acts as a request scope for the remaining execution of the function. - /// Thrown when the or the is null. - /// - /// Thrown when no could be found in the registered services or when no message correlation format could be determined. - /// - public static MessageCorrelationResult GetCorrelationInfo( - this FunctionContext context, - Dictionary applicationProperties, - MessageCorrelationFormat correlationFormat) - { - if (context is null) - { - throw new ArgumentNullException(nameof(context)); - } - - if (applicationProperties is null) - { - throw new ArgumentNullException(nameof(applicationProperties)); - } - - if (correlationFormat is MessageCorrelationFormat.W3C) - { - var telemetryClient = context.InstanceServices.GetService(); - if (telemetryClient is null) - { - throw new InvalidOperationException( - "Cannot retrieve the Microsoft telemetry client form the Azure Functions registered services, this can happen when the Application Insights packages are in conflict with each other," - + "please correct this conflict so the W3C message correlation can be determined for received events from Azure EventHubs"); - } - - (string transactionId, string operationParentId) = DetermineTraceParent(applicationProperties); - return MessageCorrelationResult.Create(telemetryClient, transactionId, operationParentId); - } - - if (correlationFormat is MessageCorrelationFormat.Hierarchical) - { - string transactionId = DetermineTransactionId(applicationProperties, PropertyNames.TransactionId); - string operationId = DetermineOperationId(applicationProperties); - string operationParentId = GetOptionalUserProperty(applicationProperties, PropertyNames.OperationParentId); - - var correlationInfo = new MessageCorrelationInfo(operationId, transactionId, operationParentId); - return MessageCorrelationResult.Create(correlationInfo); - } - - throw new InvalidOperationException( - "Cannot determine message correlation format, either choose between W3C or Hierarchical"); - } - - private static (string transactionId, string operationParentId) DetermineTraceParent(Dictionary applicationProperties) - { - IDictionary castProperties = - applicationProperties.ToDictionary( - item => item.Key, - item => (object) item.Value.GetString()); - - return castProperties.GetTraceParent(); - } - - private static string DetermineTransactionId(Dictionary properties, string transactionIdPropertyName) - { - string transactionId = GetOptionalUserProperty(properties, transactionIdPropertyName); - if (string.IsNullOrWhiteSpace(transactionId)) - { - string generatedTransactionId = Guid.NewGuid().ToString(); - return generatedTransactionId; - } - - return transactionId; - } - - private static string GetOptionalUserProperty(Dictionary properties, string propertyName) - { - if (properties.TryGetValue(propertyName, out JsonElement propertyValue)) - { - return propertyValue.ToString(); - } - - return null; - } - - private static string DetermineOperationId(Dictionary properties) - { - if (!properties.TryGetValue("CorrelationId", out JsonElement messageCorrelationId) - || string.IsNullOrWhiteSpace(messageCorrelationId.ToString())) - { - var generatedOperationId = Guid.NewGuid().ToString(); - return generatedOperationId; - } - - return messageCorrelationId.ToString(); - } - } -} diff --git a/src/Arcus.Messaging.AzureFunctions.EventHubs/Extensions/IFunctionsHostBuilderExtensions.cs b/src/Arcus.Messaging.AzureFunctions.EventHubs/Extensions/IFunctionsHostBuilderExtensions.cs deleted file mode 100644 index f848bb19..00000000 --- a/src/Arcus.Messaging.AzureFunctions.EventHubs/Extensions/IFunctionsHostBuilderExtensions.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using Arcus.Messaging.Abstractions.EventHubs.MessageHandling; -using Arcus.Messaging.AzureFunctions.EventHubs; -using Microsoft.Extensions.DependencyInjection; - -// ReSharper disable once CheckNamespace -namespace Microsoft.Azure.Functions.Extensions.DependencyInjection -{ - /// - /// Extensions on the related to Azure EventHubs message handling. - /// - // ReSharper disable once InconsistentNaming - public static class IFunctionsHostBuilderExtensions - { - /// - /// Adds an implementation - /// to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// Thrown when the is null. - public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting( - this IFunctionsHostBuilder builder) - { - return AddEventHubsMessageRouting(builder, configureOptions: null); - } - - /// - /// Adds an implementation - /// to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// The function to configure the options that change the behavior of the router. - /// Thrown when the is null. - public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting( - this IFunctionsHostBuilder builder, - Action configureOptions) - { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - return builder.Services.AddSingleton() - .AddEventHubsMessageRouting(configureOptions); - } - - /// - /// Adds an implementation - /// to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// The function to create the implementation. - /// The type of the implementation. - /// Thrown when the or is null. - public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting( - this IFunctionsHostBuilder builder, - Func implementationFactory) - where TMessageRouter : IAzureEventHubsMessageRouter - { - return AddEventHubsMessageRouting(builder, (provider, options) => implementationFactory(provider), configureOptions: null); - } - - /// - /// Adds an implementation - /// to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// The function to create the implementation. - /// The function to configure the options that change the behavior of the router. - /// The type of the implementation. - /// Thrown when the or is null. - public static EventHubsMessageHandlerCollection AddEventHubsMessageRouting( - this IFunctionsHostBuilder builder, - Func implementationFactory, - Action configureOptions) - where TMessageRouter : IAzureEventHubsMessageRouter - { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (implementationFactory is null) - { - throw new ArgumentNullException(nameof(implementationFactory)); - } - - return builder.Services.AddSingleton() - .AddEventHubsMessageRouting(implementationFactory, configureOptions); - } - } -} diff --git a/src/Arcus.Messaging.AzureFunctions.ServiceBus/Arcus.Messaging.AzureFunctions.ServiceBus.csproj b/src/Arcus.Messaging.AzureFunctions.ServiceBus/Arcus.Messaging.AzureFunctions.ServiceBus.csproj deleted file mode 100644 index 245ffde0..00000000 --- a/src/Arcus.Messaging.AzureFunctions.ServiceBus/Arcus.Messaging.AzureFunctions.ServiceBus.csproj +++ /dev/null @@ -1,43 +0,0 @@ - - - - net8.0;net6.0;netstandard2.1 - latest - Arcus - Arcus - Arcus.Messaging - Provides Azure Service Bus message handling/routing for Azure Functions. - Copyright (c) Arcus - https://messaging.arcus-azure.net/ - https://github.com/arcus-azure/arcus.messaging - LICENSE - icon.png - README.md - Git - Azure;Messaging;ServiceBus;AzureFunctions - true - true - true - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Arcus.Messaging.AzureFunctions.ServiceBus/AzureFunctionsInProcessMessageCorrelation.cs b/src/Arcus.Messaging.AzureFunctions.ServiceBus/AzureFunctionsInProcessMessageCorrelation.cs deleted file mode 100644 index 7817b9a8..00000000 --- a/src/Arcus.Messaging.AzureFunctions.ServiceBus/AzureFunctionsInProcessMessageCorrelation.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Arcus.Messaging.Abstractions; -using Azure.Messaging.ServiceBus; -using Microsoft.ApplicationInsights; - -namespace Arcus.Messaging.AzureFunctions.ServiceBus -{ - /// - /// Represents the W3C message correlation for incoming Azure Service Bus messages in in-process Azure Functions environments. - /// - public class AzureFunctionsInProcessMessageCorrelation - { - private readonly TelemetryClient _telemetryClient; - - /// - /// Initializes a new instance of the class. - /// - /// The Microsoft telemetry client to automatically track outgoing built-in Microsoft dependencies. - /// Thrown when the is null. - public AzureFunctionsInProcessMessageCorrelation(TelemetryClient client) - { - _telemetryClient = client ?? throw new ArgumentNullException(nameof(client)); - } - - /// - /// Correlate the incoming Azure Service Bus message using the W3C message correlation. - /// - /// The incoming Azure Service Bus message. - /// The disposable message correlation telemetry request scope. - /// Thrown when the is null. - public MessageCorrelationResult CorrelateMessage(ServiceBusReceivedMessage message) - { - if (message is null) - { - throw new ArgumentNullException(nameof(message)); - } - - (string transactionId, string operationParentId) = message.ApplicationProperties.GetTraceParent(); - return MessageCorrelationResult.Create(_telemetryClient, transactionId, operationParentId); - } - } -} diff --git a/src/Arcus.Messaging.AzureFunctions.ServiceBus/AzureFunctionsMessageCorrelation.cs b/src/Arcus.Messaging.AzureFunctions.ServiceBus/AzureFunctionsMessageCorrelation.cs deleted file mode 100644 index 7790f39c..00000000 --- a/src/Arcus.Messaging.AzureFunctions.ServiceBus/AzureFunctionsMessageCorrelation.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Arcus.Messaging.Abstractions; -using Azure.Messaging.ServiceBus; -using Microsoft.ApplicationInsights; - -namespace Arcus.Messaging.AzureFunctions.ServiceBus -{ - /// - /// Represents the W3C message correlation for incoming Azure Service Bus messages in in-process Azure Functions environments. - /// - public class AzureFunctionsMessageCorrelation - { - private readonly TelemetryClient _telemetryClient; - - /// - /// Initializes a new instance of the class. - /// - /// The Microsoft telemetry client to automatically track outgoing built-in Microsoft dependencies. - /// Thrown when the is null. - public AzureFunctionsMessageCorrelation(TelemetryClient client) - { - _telemetryClient = client ?? throw new ArgumentNullException(nameof(client)); - } - - /// - /// Correlate the incoming Azure Service Bus message using the W3C message correlation. - /// - /// The incoming Azure Service Bus message. - /// The disposable message correlation telemetry request scope. - /// Thrown when the is null. - public MessageCorrelationResult CorrelateMessage(ServiceBusReceivedMessage message) - { - if (message is null) - { - throw new ArgumentNullException(nameof(message)); - } - - (string transactionId, string operationParentId) = message.ApplicationProperties.GetTraceParent(); - return MessageCorrelationResult.Create(_telemetryClient, transactionId, operationParentId); - } - } -} diff --git a/src/Arcus.Messaging.AzureFunctions.ServiceBus/Extensions/FunctionContextExtensions.cs b/src/Arcus.Messaging.AzureFunctions.ServiceBus/Extensions/FunctionContextExtensions.cs deleted file mode 100644 index 6d9dca07..00000000 --- a/src/Arcus.Messaging.AzureFunctions.ServiceBus/Extensions/FunctionContextExtensions.cs +++ /dev/null @@ -1,126 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text.Json; -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.MessageHandling; -using Microsoft.ApplicationInsights; -using Microsoft.Extensions.DependencyInjection; - -// ReSharper disable once CheckNamespace -namespace Microsoft.Azure.Functions.Worker -{ -#if !NETSTANDARD2_1 - /// - /// Extensions on the related to message correlation. - /// - public static class FunctionContextExtensions - { - /// - /// Determines the W3C message correlation based on the 'UserProperties' binding data in the . - /// - /// The execution context of the executed isolated Azure Function. - /// Thrown when the is null or doesn't contain any binding data in its binding context. - /// Thrown when no 'UserProperties' binding data can be found in the . - public static MessageCorrelationResult GetCorrelationInfo(this FunctionContext context) - { - return GetCorrelationInfo(context, MessageCorrelationFormat.W3C); - } - - /// - /// Determines the message correlation based on the 'UserProperties' binding data in the . - /// - /// The execution context of the executed isolated Azure Function. - /// The type of correlation format that should be used to find the necessary correlation information in the 'UserProperties'. - /// Thrown when the is null or doesn't contain any binding data in its binding context. - /// Thrown when no 'UserProperties' binding data can be found in the . - public static MessageCorrelationResult GetCorrelationInfo(this FunctionContext context, MessageCorrelationFormat correlationFormat) - { - if (context?.BindingContext?.BindingData is null) - { - throw new ArgumentNullException(nameof(context), "Requires a function context with a binding data to retrieve the message correlation"); - } - - IDictionary userPropertiesJson = GetUserPropertiesJson(context); - switch (correlationFormat) - { - case MessageCorrelationFormat.W3C: - return GetCorrelationInfoViaW3C(context, userPropertiesJson); - case MessageCorrelationFormat.Hierarchical: - return GetCorrelationInfoViaHierarchical(userPropertiesJson); - default: - throw new ArgumentOutOfRangeException(nameof(correlationFormat), correlationFormat, "Unknown message correlation format"); - } - } - - private static MessageCorrelationResult GetCorrelationInfoViaW3C(FunctionContext context, IDictionary userPropertiesJson) - { - (string transactionIdW3C, string operationParentIdW3C) = userPropertiesJson.GetTraceParent(); - var clientForExistingParent = context.InstanceServices.GetRequiredService(); - - return MessageCorrelationResult.Create(clientForExistingParent, transactionIdW3C, operationParentIdW3C); - } - - - /// - /// Determines the Hierarchical message correlation based on the 'UserProperties' binding data in the . - /// - /// The execution context of the executed isolated Azure Function. - /// The custom property name to retrieve the transaction ID from the 'UserProperties' binding data. - /// The custom property name to retrieve the operation parent ID from the 'UserProperties' binding data. - /// Thrown when the is null or doesn't contain any binding data in its binding context. - /// Thrown when no 'UserProperties' binding data can be found in the . - public static MessageCorrelationResult GetCorrelationInfo( - this FunctionContext context, - string transactionIdPropertyName, - string operationParentIdPropertyName) - { - if (context?.BindingContext?.BindingData is null) - { - throw new ArgumentNullException(nameof(context), "Requires a function context with a binding data to retrieve the message correlation"); - } - - if (string.IsNullOrWhiteSpace(transactionIdPropertyName)) - { - throw new ArgumentException("Requires a non-blank property name to retrieve the transaction ID from the binding data", nameof(transactionIdPropertyName)); - } - - if (string.IsNullOrWhiteSpace(operationParentIdPropertyName)) - { - throw new ArgumentException("Requires a non-blank property name to retrieve the operation parent ID from the binding data", nameof(operationParentIdPropertyName)); - } - - IDictionary userPropertiesJson = GetUserPropertiesJson(context); - return GetCorrelationInfoViaHierarchical(userPropertiesJson, transactionIdPropertyName, operationParentIdPropertyName); - } - - private static MessageCorrelationResult GetCorrelationInfoViaHierarchical( - IDictionary userPropertiesJson, - string transactionIdPropertyName = PropertyNames.TransactionId, - string operationParentIdPropertyName = PropertyNames.OperationParentId) - { - userPropertiesJson.TryGetValue(transactionIdPropertyName, out object transactionIdHierarchicalValue); - userPropertiesJson.TryGetValue(operationParentIdPropertyName, out object operationParentIdHierarchical); - var operationId = Guid.NewGuid().ToString(); - var transactionId = transactionIdHierarchicalValue?.ToString() ?? Guid.NewGuid().ToString(); - - var correlationInfo = new MessageCorrelationInfo(operationId, transactionId, operationParentIdHierarchical?.ToString()); - return MessageCorrelationResult.Create(correlationInfo); - } - - private static IDictionary GetUserPropertiesJson(FunctionContext context) - { - if (context.BindingContext.BindingData.TryGetValue("UserProperties", out object userPropertiesObject) - && userPropertiesObject != null) - { - string userPropertiesJson = userPropertiesObject.ToString(); - - return JsonSerializer.Deserialize>(userPropertiesJson); - } - - - throw new InvalidOperationException( - "Cannot determine message correlation because function context does not contain any 'UserProperties' binding data"); - } - } -#endif -} diff --git a/src/Arcus.Messaging.AzureFunctions.ServiceBus/Extensions/IFunctionsHostBuilderExtensions.cs b/src/Arcus.Messaging.AzureFunctions.ServiceBus/Extensions/IFunctionsHostBuilderExtensions.cs deleted file mode 100644 index 5ea2c308..00000000 --- a/src/Arcus.Messaging.AzureFunctions.ServiceBus/Extensions/IFunctionsHostBuilderExtensions.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; -using Arcus.Messaging.AzureFunctions.ServiceBus; -using Microsoft.Extensions.DependencyInjection; - -// ReSharper disable once CheckNamespace -namespace Microsoft.Azure.Functions.Extensions.DependencyInjection -{ - /// - /// Provides extensions on the to add the Azure Service Bus router. - /// - // ReSharper disable once InconsistentNaming - public static class IFunctionsHostBuilderExtensions - { - /// - /// Adds an implementation to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// Thrown when the is null. - public static ServiceBusMessageHandlerCollection AddServiceBusMessageRouting(this IFunctionsHostBuilder builder) - { - return AddServiceBusMessageRouting(builder, configureOptions: null); - } - - /// - /// Adds an implementation to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// The function to configure the options that change the behavior of the router. - /// Thrown when the is null. - public static ServiceBusMessageHandlerCollection AddServiceBusMessageRouting( - this IFunctionsHostBuilder builder, - Action configureOptions) - { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - return builder.Services.AddSingleton() - .AddServiceBusMessageRouting(configureOptions); - } - - /// - /// Adds an implementation to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// The function to create the implementation. - /// The type of the implementation. - /// Thrown when the or is null. - public static ServiceBusMessageHandlerCollection AddServiceBusMessageRouting( - this IFunctionsHostBuilder builder, - Func implementationFactory) - where TMessageRouter : IAzureServiceBusMessageRouter - { - return AddServiceBusMessageRouting(builder, (provider, options) => implementationFactory(provider), configureOptions: null); - } - - /// - /// Adds an implementation to route the incoming messages through registered instances. - /// - /// The collection of services to add the router to. - /// The function to create the implementation. - /// The function to configure the options that change the behavior of the router. - /// The type of the implementation. - /// Thrown when the or is null. - public static ServiceBusMessageHandlerCollection AddServiceBusMessageRouting( - this IFunctionsHostBuilder builder, - Func implementationFactory, - Action configureOptions) - where TMessageRouter : IAzureServiceBusMessageRouter - { - if (builder is null) - { - throw new ArgumentNullException(nameof(builder)); - } - - return builder.Services.AddSingleton() - .AddServiceBusMessageRouting(implementationFactory, configureOptions); - } - } -} diff --git a/src/Arcus.Messaging.EventHubs.Core/EventDataBuilder.cs b/src/Arcus.Messaging.EventHubs.Core/EventDataBuilder.cs index 62f02b2a..185a5f06 100644 --- a/src/Arcus.Messaging.EventHubs.Core/EventDataBuilder.cs +++ b/src/Arcus.Messaging.EventHubs.Core/EventDataBuilder.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Text; +using System.Text.Json; using Arcus.Messaging.Abstractions; -using Newtonsoft.Json; + +#pragma warning disable CS0618 // All EventHubs-functionality will be removed anyway, so ignore deprecated correlation properties. // ReSharper disable once CheckNamespace namespace Azure.Messaging.EventHubs @@ -153,7 +155,7 @@ public EventDataBuilder WithOperationParentId( /// public EventData Build() { - string json = JsonConvert.SerializeObject(_eventBody); + string json = JsonSerializer.Serialize(_eventBody); byte[] raw = _encoding.GetBytes(json); var eventData = new EventData(raw) { diff --git a/src/Arcus.Messaging.EventHubs.Core/EventHubProducerClientMessageCorrelationOptions.cs b/src/Arcus.Messaging.EventHubs.Core/EventHubProducerClientMessageCorrelationOptions.cs index 44605948..4ce5d7e3 100644 --- a/src/Arcus.Messaging.EventHubs.Core/EventHubProducerClientMessageCorrelationOptions.cs +++ b/src/Arcus.Messaging.EventHubs.Core/EventHubProducerClientMessageCorrelationOptions.cs @@ -7,6 +7,8 @@ using Azure.Messaging.EventHubs.Producer; using Microsoft.Extensions.Logging; +#pragma warning disable CS0618 // All EventHubs-functionality will be removed anyway, so ignore deprecated correlation properties. + namespace Arcus.Messaging.EventHubs.Core { /// diff --git a/src/Arcus.Messaging.EventHubs.Core/Extensions/EventDataExtensions.cs b/src/Arcus.Messaging.EventHubs.Core/Extensions/EventDataExtensions.cs index 31103261..254a57ec 100644 --- a/src/Arcus.Messaging.EventHubs.Core/Extensions/EventDataExtensions.cs +++ b/src/Arcus.Messaging.EventHubs.Core/Extensions/EventDataExtensions.cs @@ -1,6 +1,8 @@ using System; using Arcus.Messaging.Abstractions; +#pragma warning disable CS0618 // All EventHubs-functionality will be removed anyway, so ignore deprecated correlation properties. + // ReSharper disable once CheckNamespace namespace Azure.Messaging.EventHubs { diff --git a/src/Arcus.Messaging.Health/Arcus.Messaging.Health.csproj b/src/Arcus.Messaging.Health/Arcus.Messaging.Health.csproj index 4023259e..07269b26 100644 --- a/src/Arcus.Messaging.Health/Arcus.Messaging.Health.csproj +++ b/src/Arcus.Messaging.Health/Arcus.Messaging.Health.csproj @@ -28,7 +28,10 @@ - + + + + \ No newline at end of file diff --git a/src/Arcus.Messaging.Health/Tcp/TcpHealthListener.cs b/src/Arcus.Messaging.Health/Tcp/TcpHealthListener.cs index 8c498a31..3c16bdaf 100644 --- a/src/Arcus.Messaging.Health/Tcp/TcpHealthListener.cs +++ b/src/Arcus.Messaging.Health/Tcp/TcpHealthListener.cs @@ -4,6 +4,8 @@ using System.Net; using System.Net.Sockets; using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; @@ -11,14 +13,11 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; namespace Arcus.Messaging.Health.Tcp { /// - /// Representing a TCP listener as a background process to expose an endpoint where the is being broadcasted. + /// Representing a TCP listener as a background process to expose an endpoint where the is being broadcast. /// public class TcpHealthListener : BackgroundService { @@ -27,7 +26,13 @@ public class TcpHealthListener : BackgroundService private readonly TcpHealthListenerOptions _tcpListenerOptions; private readonly ILogger _logger; - private static readonly JsonSerializerSettings SerializationSettings = CreateDefaultSerializerSettings(); + private static readonly JsonSerializerOptions SerializationOptions = new JsonSerializerOptions + { + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + Converters = { new JsonStringEnumConverter(allowIntegerValues: false) } + }; /// /// Initializes a new instance of the class. @@ -36,7 +41,7 @@ public class TcpHealthListener : BackgroundService /// The additional options to configure the TCP listener. /// The service to retrieve the current health of the application. /// Thrown when the , , or is null. - /// Thrown when the doesn't have a filled-out value. + /// Thrown when the does not have a filled-out value. public TcpHealthListener( IConfiguration configuration, TcpHealthListenerOptions tcpListenerOptions, @@ -44,7 +49,7 @@ public TcpHealthListener( : this(configuration, tcpListenerOptions, healthService, NullLogger.Instance) { } - + /// /// Initializes a new instance of the class. /// @@ -53,11 +58,11 @@ public TcpHealthListener( /// The service to retrieve the current health of the application. /// The logging implementation to write diagnostic messages during the running of the TCP listener. /// Thrown when the , , , or is null. - /// Thrown when the doesn't have a filled-out value. + /// Thrown when the does not have a filled-out value. public TcpHealthListener( IConfiguration configuration, TcpHealthListenerOptions tcpListenerOptions, - HealthCheckService healthService, + HealthCheckService healthService, ILogger logger) { _tcpListenerOptions = tcpListenerOptions ?? throw new ArgumentNullException(nameof(tcpListenerOptions)); @@ -79,31 +84,16 @@ private static int GetTcpHealthPort(IConfiguration configuration, string tcpHeal return tcpPort; } - private static JsonSerializerSettings CreateDefaultSerializerSettings() - { - var serializingSettings = new JsonSerializerSettings - { - Formatting = Formatting.None, - NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new CamelCasePropertyNamesContractResolver() - }; - - var enumConverter = new StringEnumConverter { AllowIntegerValues = false }; - serializingSettings.Converters.Add(enumConverter); - - return serializingSettings; - } - /// /// Gets the port on which the TCP health server is listening to. /// public int Port { get; } /// - /// Gets the flag indicating whether or not the TCP probe is listening for client connections. + /// Gets the flag indicating whether the TCP probe is listening for client connections. /// internal bool IsListening => _listener.Active; - + /// /// Triggered when the application host is ready to start the service. /// @@ -126,10 +116,10 @@ internal void StartListeningForTcpConnections() /// /// This method is called when the starts. The implementation should return a task that represents - /// the lifetime of the long running operation(s) being performed. + /// the lifetime of the long-running operation(s) being performed. /// /// Triggered when is called. - /// A that represents the long running operations. + /// A that represents the long-running operations. protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) @@ -158,7 +148,7 @@ private async Task AcceptConnectionAsync(HealthReport report, CancellationToken if (report.Status != HealthStatus.Healthy) { - _logger.LogWarning($"Health probe is reporting '{report.Status}' status"); + _logger.LogWarning("Health probe is reporting '{Status}' status", report.Status); } byte[] response = SerializeHealthReport(report); @@ -178,7 +168,7 @@ private byte[] SerializeHealthReport(HealthReport healthReport) if (reportSerializer is null) { HealthReport updatedReport = RemoveExceptionDetails(healthReport); - string json = JsonConvert.SerializeObject(updatedReport, SerializationSettings); + string json = JsonSerializer.Serialize(updatedReport, SerializationOptions); byte[] response = Encoding.UTF8.GetBytes(json); return response; diff --git a/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IMessagePumpCircuitBreakerExtensions.cs b/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IMessagePumpCircuitBreakerExtensions.cs index c1e61dac..237e7850 100644 --- a/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IMessagePumpCircuitBreakerExtensions.cs +++ b/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IMessagePumpCircuitBreakerExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using GuardNet; // ReSharper disable once CheckNamespace namespace Arcus.Messaging.Pumps.Abstractions.Resiliency @@ -21,8 +20,15 @@ public static async Task PauseMessageProcessingAsync( this IMessagePumpCircuitBreaker circuitBreaker, string jobId) { - Guard.NotNull(circuitBreaker, nameof(circuitBreaker)); - Guard.NotNullOrWhitespace(jobId, nameof(jobId)); + if (circuitBreaker is null) + { + throw new ArgumentNullException(nameof(circuitBreaker)); + } + + if (string.IsNullOrWhiteSpace(jobId)) + { + throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId)); + } await circuitBreaker.PauseMessageProcessingAsync(jobId, _ => { }); } diff --git a/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IServiceCollectionExtensions.cs b/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IServiceCollectionExtensions.cs index e3fb1753..557577c0 100644 --- a/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IServiceCollectionExtensions.cs +++ b/src/Arcus.Messaging.Pumps.Abstractions/Extensions/IServiceCollectionExtensions.cs @@ -1,7 +1,6 @@ using System; using Arcus.Messaging.Pumps.Abstractions; using Arcus.Messaging.Pumps.Abstractions.Resiliency; -using GuardNet; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; @@ -26,8 +25,15 @@ public static IServiceCollection AddMessagePump( Func implementationFactory) where TMessagePump : MessagePump { - Guard.NotNull(services, nameof(services), "Requires an application services instance to register the custom message pump instance"); - Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a factory implementation function to create the custom message pump instance"); + if (services is null) + { + throw new ArgumentNullException(nameof(services)); + } + + if (implementationFactory is null) + { + throw new ArgumentNullException(nameof(implementationFactory)); + } services.TryAddSingleton(); services.TryAddSingleton( diff --git a/src/Arcus.Messaging.Pumps.Abstractions/Resiliency/DefaultMessagePumpCircuitBreaker.cs b/src/Arcus.Messaging.Pumps.Abstractions/Resiliency/DefaultMessagePumpCircuitBreaker.cs index dc3c6490..8f925e86 100644 --- a/src/Arcus.Messaging.Pumps.Abstractions/Resiliency/DefaultMessagePumpCircuitBreaker.cs +++ b/src/Arcus.Messaging.Pumps.Abstractions/Resiliency/DefaultMessagePumpCircuitBreaker.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Threading.Tasks; -using GuardNet; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -26,9 +25,7 @@ public class DefaultMessagePumpCircuitBreaker : IMessagePumpCircuitBreaker /// Thrown when the is null. public DefaultMessagePumpCircuitBreaker(IServiceProvider serviceProvider, ILogger logger) { - Guard.NotNull(serviceProvider, nameof(serviceProvider)); - - _serviceProvider = serviceProvider; + _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); _logger = logger ?? NullLogger.Instance; } @@ -40,7 +37,10 @@ public DefaultMessagePumpCircuitBreaker(IServiceProvider serviceProvider, ILogge /// Thrown when the is blank. public virtual Task PauseMessageProcessingAsync(string jobId, Action configureOptions) { - Guard.NotNullOrWhitespace(jobId, nameof(jobId)); + if (string.IsNullOrWhiteSpace(jobId)) + { + throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId)); + } MessagePump messagePump = GetRegisteredMessagePump(jobId); @@ -69,7 +69,10 @@ public virtual Task PauseMessageProcessingAsync(string jobId, ActionThrown when the is blank. public MessagePumpCircuitState GetCircuitBreakerState(string jobId) { - Guard.NotNullOrWhitespace(jobId, nameof(jobId)); + if (string.IsNullOrWhiteSpace(jobId)) + { + throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId)); + } MessagePump messagePump = GetRegisteredMessagePump(jobId); return messagePump.CircuitState; @@ -82,7 +85,10 @@ public MessagePumpCircuitState GetCircuitBreakerState(string jobId) /// Thrown when not a single or more than one message pump could be found by the configured job ID. protected MessagePump GetRegisteredMessagePump(string jobId) { - Guard.NotNullOrWhitespace(jobId, nameof(jobId)); + if (string.IsNullOrWhiteSpace(jobId)) + { + throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId)); + } MessagePump[] messagePumps = _serviceProvider.GetServices() diff --git a/src/Arcus.Messaging.Pumps.EventHubs/AzureEventHubsMessagePump.cs b/src/Arcus.Messaging.Pumps.EventHubs/AzureEventHubsMessagePump.cs index 37d7b732..4c150b2e 100644 --- a/src/Arcus.Messaging.Pumps.EventHubs/AzureEventHubsMessagePump.cs +++ b/src/Arcus.Messaging.Pumps.EventHubs/AzureEventHubsMessagePump.cs @@ -14,6 +14,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +#pragma warning disable CS0618 // Deprecated functionality will be removed in v3.0. + namespace Arcus.Messaging.Pumps.EventHubs { /// diff --git a/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusClient.cs b/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusClient.cs index 00e6cdb0..d3a4df02 100644 --- a/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusClient.cs +++ b/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusClient.cs @@ -9,6 +9,7 @@ namespace Arcus.Messaging.Pumps.ServiceBus /// /// Represents a client to interact with a Azure Service Bus. /// + [Obsolete("Will be removed in v3.0 as the pump project will solely focus on providing message routing functionality")] public class AzureServiceBusClient { private readonly IAzureServiceBusManagementAuthentication _authentication; diff --git a/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusMessagePump.cs b/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusMessagePump.cs index 7f745c91..3ccf4635 100644 --- a/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusMessagePump.cs +++ b/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusMessagePump.cs @@ -486,9 +486,11 @@ private MessageCorrelationResult DetermineMessageCorrelation(ServiceBusReceivedM } MessageCorrelationInfo correlationInfo = +#pragma warning disable CS0618 // Type or member is obsolete: will be removed in v3.0, once the 'Hierarchical' correlation format is removed. message.GetCorrelationInfo( Settings.Options.Routing.Correlation?.TransactionIdPropertyName ?? PropertyNames.TransactionId, Settings.Options.Routing.Correlation?.OperationParentIdPropertyName ?? PropertyNames.OperationParentId); +#pragma warning restore CS0618 // Type or member is obsolete return MessageCorrelationResult.Create(correlationInfo); } diff --git a/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusNamespace.cs b/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusNamespace.cs index fa2dbb30..6237d524 100644 --- a/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusNamespace.cs +++ b/src/Arcus.Messaging.Pumps.ServiceBus/AzureServiceBusNamespace.cs @@ -6,6 +6,7 @@ namespace Arcus.Messaging.Pumps.ServiceBus /// /// Represents the namespace of a Azure Service Bus resource; where the Azure Service Bus is located. /// + [Obsolete("Will be removed in v3.0 as the pump project will solely focus on providing message routing functionality")] public class AzureServiceBusNamespace { /// diff --git a/src/Arcus.Messaging.Pumps.ServiceBus/Configuration/AzureServiceBusCorrelationOptions.cs b/src/Arcus.Messaging.Pumps.ServiceBus/Configuration/AzureServiceBusCorrelationOptions.cs index cf7a16c7..b9bd4a3e 100644 --- a/src/Arcus.Messaging.Pumps.ServiceBus/Configuration/AzureServiceBusCorrelationOptions.cs +++ b/src/Arcus.Messaging.Pumps.ServiceBus/Configuration/AzureServiceBusCorrelationOptions.cs @@ -2,13 +2,15 @@ using Arcus.Messaging.Abstractions; using Arcus.Messaging.Abstractions.MessageHandling; +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. + namespace Arcus.Messaging.Pumps.ServiceBus.Configuration { /// /// Represents the user-configurable options to control the correlation information tracking /// during the receiving of the Azure Service Bus messages in the . /// - [Obsolete("Will use the " + nameof(MessageCorrelationOptions) + " in the future")] + [Obsolete("Will be removed in v3.0 as the options model is only used in the deprecated 'Hierarchical' correlation format")] public class AzureServiceBusCorrelationOptions { private readonly MessageCorrelationOptions _correlationOptions; diff --git a/src/Arcus.Messaging.Pumps.ServiceBus/DefaultAzureServiceBusManagementAuthentication.cs b/src/Arcus.Messaging.Pumps.ServiceBus/DefaultAzureServiceBusManagementAuthentication.cs index b6f45928..90d186ed 100644 --- a/src/Arcus.Messaging.Pumps.ServiceBus/DefaultAzureServiceBusManagementAuthentication.cs +++ b/src/Arcus.Messaging.Pumps.ServiceBus/DefaultAzureServiceBusManagementAuthentication.cs @@ -11,6 +11,7 @@ namespace Arcus.Messaging.Pumps.ServiceBus /// /// Represents the authentication with the Azure Service Bus. /// + [Obsolete("Will be removed in v3.0 as the pump project will solely focus on providing message routing functionality")] public class DefaultAzureServiceBusManagementAuthentication : IAzureServiceBusManagementAuthentication { private readonly string _clientId, _clientSecretKey, _subscriptionId, _tenantId; diff --git a/src/Arcus.Messaging.Pumps.ServiceBus/IAzureServiceBusManagementAuthentication.cs b/src/Arcus.Messaging.Pumps.ServiceBus/IAzureServiceBusManagementAuthentication.cs index bca25c94..629fa42d 100644 --- a/src/Arcus.Messaging.Pumps.ServiceBus/IAzureServiceBusManagementAuthentication.cs +++ b/src/Arcus.Messaging.Pumps.ServiceBus/IAzureServiceBusManagementAuthentication.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Microsoft.Azure.Management.ServiceBus; namespace Arcus.Messaging.Pumps.ServiceBus @@ -6,6 +7,7 @@ namespace Arcus.Messaging.Pumps.ServiceBus /// /// Represents the contract on how to authenticate with the Azure Service Bus. /// + [Obsolete("Will be removed in v3.0 as the pump project will solely focus on providing message routing functionality")] public interface IAzureServiceBusManagementAuthentication { /// diff --git a/src/Arcus.Messaging.ServiceBus.Core/Extensions/MessageExtensions.cs b/src/Arcus.Messaging.ServiceBus.Core/Extensions/MessageExtensions.cs index 5211adde..23b33989 100644 --- a/src/Arcus.Messaging.ServiceBus.Core/Extensions/MessageExtensions.cs +++ b/src/Arcus.Messaging.ServiceBus.Core/Extensions/MessageExtensions.cs @@ -3,6 +3,8 @@ using Arcus.Messaging.Abstractions; using Azure.Messaging.ServiceBus; +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. + // ReSharper disable once CheckNamespace namespace Microsoft.Azure.ServiceBus { @@ -59,7 +61,7 @@ public static TProperty GetApplicationProperty(this ServiceBusReceive /// otherwise both will be generated GUID's. /// /// Thrown when the is null. - [Obsolete("Use the 'GetCorrelationInfo' extension in the 'Azure.Messaging.ServiceBus' namespace, remove the 'Microsoft.Azure.ServiceBus' namespace from your using statements")] + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedMessage message) { return GetCorrelationInfo(message, PropertyNames.TransactionId); @@ -77,7 +79,7 @@ public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedM /// /// Thrown when the . /// Thrown when the is blank. - [Obsolete("Use the 'GetCorrelationInfo' extension in the 'Azure.Messaging.ServiceBus' namespace, remove the 'Microsoft.Azure.ServiceBus' namespace from your using statements")] + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedMessage message, string transactionIdPropertyName) { MessageCorrelationInfo messageCorrelationInfo = @@ -101,7 +103,7 @@ public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedM /// /// Thrown when the or the is blank. /// - [Obsolete("Use the 'GetCorrelationInfo' extension in the 'Azure.Messaging.ServiceBus' namespace, remove the 'Microsoft.Azure.ServiceBus' namespace from your using statements")] + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static MessageCorrelationInfo GetCorrelationInfo( this ServiceBusReceivedMessage message, string transactionIdPropertyName, @@ -161,7 +163,7 @@ private static string DetermineOperationId(string messageCorrelationId) /// The correlation transaction ID for message if an application property could be found with the key ; null otherwise. /// /// Thrown when the is null. - [Obsolete("Use the 'GetTransactionId' extension in the 'Azure.Messaging.ServiceBus' namespace, remove the 'Microsoft.Azure.ServiceBus' namespace from your using statements")] + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static string GetTransactionId(this ServiceBusReceivedMessage message) { return GetTransactionId(message, PropertyNames.TransactionId); @@ -177,7 +179,7 @@ public static string GetTransactionId(this ServiceBusReceivedMessage message) /// /// Thrown when the is null. /// Thrown when the is blank. - [Obsolete("Use the 'GetTransactionId' extension in the 'Azure.Messaging.ServiceBus' namespace, remove the 'Microsoft.Azure.ServiceBus' namespace from your using statements")] + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static string GetTransactionId(this ServiceBusReceivedMessage message, string transactionIdPropertyName) { if (message is null) diff --git a/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusReceivedMessageExtensions.cs b/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusReceivedMessageExtensions.cs index b375f57f..a246c07f 100644 --- a/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusReceivedMessageExtensions.cs +++ b/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusReceivedMessageExtensions.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using Arcus.Messaging.Abstractions; +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. + // ReSharper disable once CheckNamespace namespace Azure.Messaging.ServiceBus { @@ -20,6 +22,7 @@ public static class ServiceBusReceivedMessageExtensions /// Thrown when the is blank. /// Thrown when there's no application property for the provided . /// Thrown when the application property's value cannot be cast to the provided type. + [Obsolete("Will be removed in v3.0 as the extension is not providing enough added-value")] public static TProperty GetApplicationProperty(this ServiceBusReceivedMessage message, string key) { if (message is null) @@ -61,6 +64,7 @@ public static TProperty GetApplicationProperty(this ServiceBusReceive /// otherwise both will be generated GUID's. /// /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedMessage message) { return GetCorrelationInfo(message, PropertyNames.TransactionId); @@ -82,6 +86,7 @@ public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedM /// /// Thrown when the . /// Thrown when the is blank. + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedMessage message, string transactionIdPropertyName) { MessageCorrelationInfo messageCorrelationInfo = @@ -109,6 +114,7 @@ public static MessageCorrelationInfo GetCorrelationInfo(this ServiceBusReceivedM /// /// Thrown when the or the is blank. /// + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static MessageCorrelationInfo GetCorrelationInfo( this ServiceBusReceivedMessage message, string transactionIdPropertyName, @@ -137,6 +143,7 @@ public static MessageCorrelationInfo GetCorrelationInfo( return messageCorrelationInfo; } + [Obsolete("Will be removed in v3.0")] private static string DetermineTransactionId(ServiceBusReceivedMessage message, string transactionIdPropertyName) { string transactionId = GetTransactionId(message, transactionIdPropertyName); @@ -172,6 +179,7 @@ private static string DetermineOperationId(string messageCorrelationId) /// The correlation transaction ID for message if an application property could be found with the key ; null otherwise. /// /// Thrown when the is null. + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static string GetTransactionId(this ServiceBusReceivedMessage message) { return GetTransactionId(message, PropertyNames.TransactionId); @@ -191,6 +199,7 @@ public static string GetTransactionId(this ServiceBusReceivedMessage message) /// /// Thrown when the is null. /// Thrown when the is blank. + [Obsolete("Will be removed in v3.0 as the extension on the Azure Service bus message is only used for the deprecated 'Hierarchical' correlation format")] public static string GetTransactionId(this ServiceBusReceivedMessage message, string transactionIdPropertyName) { if (message is null) diff --git a/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusSenderExtensions.cs b/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusSenderExtensions.cs index 7acc771f..ebf83e8e 100644 --- a/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusSenderExtensions.cs +++ b/src/Arcus.Messaging.ServiceBus.Core/Extensions/ServiceBusSenderExtensions.cs @@ -8,6 +8,8 @@ using Arcus.Observability.Telemetry.Core; using Microsoft.Extensions.Logging; +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. + // ReSharper disable once CheckNamespace namespace Azure.Messaging.ServiceBus { @@ -31,6 +33,7 @@ public static class ServiceBusSenderExtensions /// For more information on service limits, see /// . /// + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] public static async Task SendMessageAsync( this ServiceBusSender sender, object messageBody, @@ -57,6 +60,7 @@ public static async Task SendMessageAsync( /// For more information on service limits, see /// . /// + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] public static async Task SendMessageAsync( this ServiceBusSender sender, object messageBody, @@ -69,131 +73,135 @@ public static async Task SendMessageAsync( } /// - /// Sends a set of messages to the associated Service Bus entity using a batched approach. - /// If the size of the messages exceed the maximum size of a single batch, - /// an exception will be triggered and the send will fail. In order to ensure that the messages - /// being sent will fit in a batch, use instead. + /// Sends a message to the associated entity of Service Bus. /// - /// The Azure Service Bus sender when sending the . - /// The set of message bodies to send as Azure Service Bus messages. - /// The message correlation instance to enrich the to-be-created messages with. + /// The Azure Service Bus sender when sending the + /// The message to send. + /// The message correlation instance to enrich the with. /// The logger instance to track the Azure Service Bus dependency. /// An optional instance to signal the request to cancel the operation. /// A task to be resolved on when the operation has completed. - /// Thrown when the , , or is null. - /// Thrown when the doesn't contain any elements or has any null elements. /// - /// The set of messages exceeds the maximum size allowed in a single batch, as determined by the Service Bus service. + /// The message exceeds the maximum size allowed, as determined by the Service Bus service. /// The will be set to in this case. /// For more information on service limits, see /// . /// - public static async Task SendMessagesAsync( + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] + public static async Task SendMessageAsync( this ServiceBusSender sender, - IEnumerable messageBodies, + ServiceBusMessage message, CorrelationInfo correlationInfo, ILogger logger, CancellationToken cancellationToken = default(CancellationToken)) { - await SendMessagesAsync(sender, messageBodies, correlationInfo, logger, configureOptions: null, cancellationToken); + await SendMessageAsync(sender, message, correlationInfo, logger, configureOptions: null, cancellationToken); } /// - /// Sends a set of messages to the associated Service Bus entity using a batched approach. - /// If the size of the messages exceed the maximum size of a single batch, - /// an exception will be triggered and the send will fail. In order to ensure that the messages - /// being sent will fit in a batch, use instead. + /// Sends a message to the associated entity of Service Bus. /// - /// The Azure Service Bus sender when sending the . - /// The set of message bodies to send as Azure Service Bus messages. - /// The message correlation instance to enrich the to-be-created messages with. + /// The Azure Service Bus sender when sending the + /// The message to send. + /// The message correlation instance to enrich the with. /// The logger instance to track the Azure Service Bus dependency. - /// The function to configure additional options to the correlated messages. + /// The function to configure additional options to the correlated . /// An optional instance to signal the request to cancel the operation. /// A task to be resolved on when the operation has completed. - /// Thrown when the , , or is null. - /// Thrown when the doesn't contain any elements or has any null elements. /// - /// The set of messages exceeds the maximum size allowed in a single batch, as determined by the Service Bus service. + /// The message exceeds the maximum size allowed, as determined by the Service Bus service. /// The will be set to in this case. /// For more information on service limits, see /// . /// - public static async Task SendMessagesAsync( + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] + public static async Task SendMessageAsync( this ServiceBusSender sender, - IEnumerable messageBodies, + ServiceBusMessage message, CorrelationInfo correlationInfo, ILogger logger, Action configureOptions, CancellationToken cancellationToken = default(CancellationToken)) { - if (messageBodies is null) + if (message is null) { - throw new ArgumentNullException(nameof(messageBodies)); + throw new ArgumentNullException(nameof(message)); } - ServiceBusMessage[] messages = - messageBodies.Select(messageBody => ServiceBusMessageBuilder.CreateForBody(messageBody).Build()) - .ToArray(); - - await SendMessagesAsync(sender, messages, correlationInfo, logger, configureOptions, cancellationToken); + await SendMessagesAsync(sender, new[] { message }, correlationInfo, logger, configureOptions, cancellationToken); } /// - /// Sends a message to the associated entity of Service Bus. + /// Sends a set of messages to the associated Service Bus entity using a batched approach. + /// If the size of the messages exceed the maximum size of a single batch, + /// an exception will be triggered and the send will fail. In order to ensure that the messages + /// being sent will fit in a batch, use instead. /// - /// The Azure Service Bus sender when sending the - /// The message to send. - /// The message correlation instance to enrich the with. + /// The Azure Service Bus sender when sending the . + /// The set of message bodies to send as Azure Service Bus messages. + /// The message correlation instance to enrich the to-be-created messages with. /// The logger instance to track the Azure Service Bus dependency. /// An optional instance to signal the request to cancel the operation. /// A task to be resolved on when the operation has completed. + /// Thrown when the , , or is null. + /// Thrown when the doesn't contain any elements or has any null elements. /// - /// The message exceeds the maximum size allowed, as determined by the Service Bus service. + /// The set of messages exceeds the maximum size allowed in a single batch, as determined by the Service Bus service. /// The will be set to in this case. /// For more information on service limits, see /// . /// - public static async Task SendMessageAsync( + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] + public static async Task SendMessagesAsync( this ServiceBusSender sender, - ServiceBusMessage message, + IEnumerable messageBodies, CorrelationInfo correlationInfo, ILogger logger, CancellationToken cancellationToken = default(CancellationToken)) { - await SendMessageAsync(sender, message, correlationInfo, logger, configureOptions: null, cancellationToken); + await SendMessagesAsync(sender, messageBodies, correlationInfo, logger, configureOptions: null, cancellationToken); } /// - /// Sends a message to the associated entity of Service Bus. + /// Sends a set of messages to the associated Service Bus entity using a batched approach. + /// If the size of the messages exceed the maximum size of a single batch, + /// an exception will be triggered and the send will fail. In order to ensure that the messages + /// being sent will fit in a batch, use instead. /// - /// The Azure Service Bus sender when sending the - /// The message to send. - /// The message correlation instance to enrich the with. + /// The Azure Service Bus sender when sending the . + /// The set of message bodies to send as Azure Service Bus messages. + /// The message correlation instance to enrich the to-be-created messages with. /// The logger instance to track the Azure Service Bus dependency. - /// The function to configure additional options to the correlated . + /// The function to configure additional options to the correlated messages. /// An optional instance to signal the request to cancel the operation. /// A task to be resolved on when the operation has completed. + /// Thrown when the , , or is null. + /// Thrown when the doesn't contain any elements or has any null elements. /// - /// The message exceeds the maximum size allowed, as determined by the Service Bus service. + /// The set of messages exceeds the maximum size allowed in a single batch, as determined by the Service Bus service. /// The will be set to in this case. /// For more information on service limits, see /// . /// - public static async Task SendMessageAsync( + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] + public static async Task SendMessagesAsync( this ServiceBusSender sender, - ServiceBusMessage message, + IEnumerable messageBodies, CorrelationInfo correlationInfo, ILogger logger, Action configureOptions, CancellationToken cancellationToken = default(CancellationToken)) { - if (message is null) + if (messageBodies is null) { - throw new ArgumentNullException(nameof(message)); + throw new ArgumentNullException(nameof(messageBodies)); } - await SendMessagesAsync(sender, new[] { message }, correlationInfo, logger, configureOptions, cancellationToken); + ServiceBusMessage[] messages = + messageBodies.Select(messageBody => ServiceBusMessageBuilder.CreateForBody(messageBody).Build()) + .ToArray(); + + await SendMessagesAsync(sender, messages, correlationInfo, logger, configureOptions, cancellationToken); } /// @@ -216,6 +224,7 @@ public static async Task SendMessageAsync( /// For more information on service limits, see /// . /// + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] public static async Task SendMessagesAsync( this ServiceBusSender sender, IEnumerable messages, @@ -247,6 +256,7 @@ public static async Task SendMessagesAsync( /// For more information on service limits, see /// . /// + [Obsolete("Will be removed in v3.0 as this extension on the Azure Service bus sender is only used in the deprecated 'Hierarchical' correlation format")] public static async Task SendMessagesAsync( this ServiceBusSender sender, IEnumerable messages, diff --git a/src/Arcus.Messaging.ServiceBus.Core/ServiceBusMessageBuilder.cs b/src/Arcus.Messaging.ServiceBus.Core/ServiceBusMessageBuilder.cs index 266303a9..f46ff4d8 100644 --- a/src/Arcus.Messaging.ServiceBus.Core/ServiceBusMessageBuilder.cs +++ b/src/Arcus.Messaging.ServiceBus.Core/ServiceBusMessageBuilder.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using System.Text.Json; using Arcus.Messaging.Abstractions; -using Newtonsoft.Json; +using Arcus.Messaging.Abstractions.MessageHandling; + +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. // ReSharper disable once CheckNamespace namespace Azure.Messaging.ServiceBus @@ -10,6 +13,7 @@ namespace Azure.Messaging.ServiceBus /// /// Represents a builder instance to create instances in different ways. /// + [Obsolete("Will be removed in v3.0 as this builder is only used when Azure Service bus messages are send with the deprecated " + nameof(MessageCorrelationFormat.Hierarchical) + " correlation format")] public class ServiceBusMessageBuilder { private readonly object _messageBody; @@ -150,7 +154,7 @@ public ServiceBusMessageBuilder WithOperationParentId( /// public ServiceBusMessage Build() { - string json = JsonConvert.SerializeObject(_messageBody); + string json = JsonSerializer.Serialize(_messageBody); byte[] raw = _encoding.GetBytes(json); var message = new ServiceBusMessage(raw) { diff --git a/src/Arcus.Messaging.ServiceBus.Core/ServiceBusSenderMessageCorrelationOptions.cs b/src/Arcus.Messaging.ServiceBus.Core/ServiceBusSenderMessageCorrelationOptions.cs index 66406e37..9a56b773 100644 --- a/src/Arcus.Messaging.ServiceBus.Core/ServiceBusSenderMessageCorrelationOptions.cs +++ b/src/Arcus.Messaging.ServiceBus.Core/ServiceBusSenderMessageCorrelationOptions.cs @@ -2,15 +2,19 @@ using System.Collections.Generic; using System.Threading; using Arcus.Messaging.Abstractions; +using Arcus.Messaging.Abstractions.MessageHandling; using Arcus.Observability.Correlation; using Azure.Messaging.ServiceBus; using Microsoft.Extensions.Logging; +#pragma warning disable S1133 // Disable usage of deprecated functionality until v3.0 is released. + namespace Arcus.Messaging.ServiceBus.Core { /// /// Represents the user-configurable options to influence the message correlation tracking behavior of the extensions. /// + [Obsolete("Will be removed in v3.0 as this options model is only used in the deprecated " + nameof(MessageCorrelationFormat.Hierarchical) + " correlation format")] public class ServiceBusSenderMessageCorrelationOptions { private string _transactionIdPropertyName = PropertyNames.TransactionId; diff --git a/src/Arcus.Messaging.Tests.Core/Arcus.Messaging.Tests.Core.csproj b/src/Arcus.Messaging.Tests.Core/Arcus.Messaging.Tests.Core.csproj index 86479dc3..5f3927d1 100644 --- a/src/Arcus.Messaging.Tests.Core/Arcus.Messaging.Tests.Core.csproj +++ b/src/Arcus.Messaging.Tests.Core/Arcus.Messaging.Tests.Core.csproj @@ -17,7 +17,6 @@ - diff --git a/src/Arcus.Messaging.Tests.Docker.dcproj b/src/Arcus.Messaging.Tests.Docker.dcproj deleted file mode 100644 index 29baf54b..00000000 --- a/src/Arcus.Messaging.Tests.Docker.dcproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 2.1 - Linux - 49d85a35-f341-47a3-887f-68dec06cebca - LaunchBrowser - arcus.messaging.tests.docker - - - - docker-compose.yml - - - - - \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Integration/Arcus.Messaging.Tests.Integration.csproj b/src/Arcus.Messaging.Tests.Integration/Arcus.Messaging.Tests.Integration.csproj index 86b2b98f..ca377846 100644 --- a/src/Arcus.Messaging.Tests.Integration/Arcus.Messaging.Tests.Integration.csproj +++ b/src/Arcus.Messaging.Tests.Integration/Arcus.Messaging.Tests.Integration.csproj @@ -40,10 +40,10 @@ - + Always - + Always diff --git a/src/Arcus.Messaging.Tests.Integration/Health/HealthReportEntryConverter.cs b/src/Arcus.Messaging.Tests.Integration/Health/HealthReportEntryConverter.cs deleted file mode 100644 index 5812ac40..00000000 --- a/src/Arcus.Messaging.Tests.Integration/Health/HealthReportEntryConverter.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using Microsoft.Extensions.Diagnostics.HealthChecks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Arcus.Messaging.Tests.Integration.Health -{ - /// - /// JSON converter to deserialize struct. - /// The structs is not correctly deserialized since it was not especially made to be deserialized; - /// also structs are naturally not made for deserialization using Newtonsoft.Json. - /// - public class HealthReportEntryConverter : JsonConverter - { - /// Writes the JSON representation of the object. - /// The to write to. - /// The value. - /// The calling serializer. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - /// Reads the JSON representation of the object. - /// The to read from. - /// Type of the object. - /// The existing value of object being read. - /// The calling serializer. - /// The object value. - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - JToken token = JToken.Load(reader); - - var healthStatus = token["status"].ToObject(); - var description = token["description"]?.ToObject(); - var duration = token["duration"].ToObject(); - var exception = token["exception"]?.ToObject(); - var data = token["data"]?.ToObject>(); - var readOnlyDictionary = new ReadOnlyDictionary(data ?? new Dictionary()); - var tags = token["tags"]?.ToObject(); - - return new HealthReportEntry(healthStatus, description, duration, exception, readOnlyDictionary, tags); - } - - /// - /// Determines whether this instance can convert the specified object type. - /// - /// Type of the object. - /// - /// true if this instance can convert the specified object type; otherwise, false. - /// - public override bool CanConvert(Type objectType) - { - return typeof(HealthReportEntry) == objectType; - } - } -} diff --git a/src/Arcus.Messaging.Tests.Integration/Health/HealthReportEntryConverterTests.cs b/src/Arcus.Messaging.Tests.Integration/Health/HealthReportEntryConverterTests.cs deleted file mode 100644 index 97f1d27c..00000000 --- a/src/Arcus.Messaging.Tests.Integration/Health/HealthReportEntryConverterTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using Microsoft.Extensions.Diagnostics.HealthChecks; -using Newtonsoft.Json; -using Xunit; - -namespace Arcus.Messaging.Tests.Integration.Health -{ - public class HealthReportEntryConverterTests - { - [Fact] - public void Deserialize_HealthReportWithoutException_Succeeds() - { - // Arrange - string json = - @"{""Entries"": - {""sample"": - {""Data"":{""key"":""value""}, - ""Description"":""desc"", - ""Duration"":""00:00:05"", - ""Status"":2, - ""Tags"":[""tag1""]}},""Status"":2,""TotalDuration"":""00:00:05""}"; - - - // Act - var report = JsonConvert.DeserializeObject(json, new HealthReportEntryConverter()); - - // Assert - Assert.NotNull(report); - Assert.Equal(HealthStatus.Healthy, report.Status); - - (string entryName, HealthReportEntry entry) = Assert.Single(report.Entries); - Assert.Equal("sample", entryName); - Assert.Equal(HealthStatus.Healthy, entry.Status); - Assert.Equal("desc", entry.Description); - - (string key, object data) = Assert.Single(entry.Data); - Assert.Equal("key", key); - Assert.Equal("value", data); - Assert.Equal(TimeSpan.FromSeconds(5), entry.Duration); - - string tag = Assert.Single(entry.Tags); - Assert.Equal("tag1", tag); - } - } -} diff --git a/src/Arcus.Messaging.Tests.Integration/Health/TcpHealthService.cs b/src/Arcus.Messaging.Tests.Integration/Health/TcpHealthService.cs index 38a684c2..0347c0e3 100644 --- a/src/Arcus.Messaging.Tests.Integration/Health/TcpHealthService.cs +++ b/src/Arcus.Messaging.Tests.Integration/Health/TcpHealthService.cs @@ -21,7 +21,7 @@ namespace Arcus.Messaging.Tests.Integration.Health public class TcpHealthService { private const string LocalAddress = "127.0.0.1"; - + private readonly int _healthTcpPort; private readonly ILogger _logger; @@ -48,7 +48,7 @@ public async Task GetHealthReportAsync() _logger.LogTrace("Connecting to the TCP {Address}:{Port}...", LocalAddress, _healthTcpPort); await client.ConnectAsync(IPAddress.Parse(LocalAddress), _healthTcpPort); _logger.LogTrace("Connected to the TCP {Address}:{Port}", LocalAddress, _healthTcpPort); - + _logger.LogTrace("Retrieving health report..."); using (NetworkStream clientStream = client.GetStream()) using (var reader = new StreamReader(clientStream)) @@ -60,12 +60,13 @@ public async Task GetHealthReportAsync() && json.TryGetValue("status", out JToken status) && json.TryGetValue("totalDuration", out JToken totalDuration)) { - HealthReport report = ParseHealthReport(entries, status, totalDuration); + HealthReport report = ParseHealthReport(entries, status, totalDuration); - _logger.LogTrace("Health report retrieved"); + _logger.LogTrace("Health report retrieved"); return report; } + _logger.LogError("Could not find necessary camelCase health report properties from: {Json}", json); return null; } } @@ -85,7 +86,7 @@ private static HealthReport ParseHealthReport(JToken entries, JToken status, JTo new ReadOnlyDictionary(reportEntries), healthStatus, duration); - + return report; } diff --git a/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.RouterTests.cs b/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.RouterTests.cs index 95f1c47d..c022c1a9 100644 --- a/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.RouterTests.cs +++ b/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.RouterTests.cs @@ -26,8 +26,8 @@ public async Task ServiceBusTopicMessagePumpWithBodyFiltering_RoutesServiceBusMe await TestServiceBusMessageHandlingAsync(Topic, options => { options.AddServiceBusTopicMessagePumpUsingManagedIdentity(TopicName, HostName) - .WithServiceBusMessageHandler((Customer body) => body is null) - .WithServiceBusMessageHandler((Order body) => body.Id != null) + .WithServiceBusMessageHandler(opt => opt.AddMessageBodyFilter(body => body is null)) + .WithServiceBusMessageHandler(opt => opt.AddMessageBodyFilter(body => body.Id != null)) .WithMessageHandler((Order _) => false); }); } @@ -38,16 +38,16 @@ public async Task ServiceBusQueueMessagePumpWithContextAndBodyFilteringWithSeria await TestServiceBusMessageHandlingAsync(Queue, options => { options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = true) - .WithServiceBusMessageHandler(messageContextFilter: _ => false) - .WithServiceBusMessageHandler(messageBodyFilter: _ => true) + .WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => false)) + .WithServiceBusMessageHandler(opt => opt.AddMessageBodyFilter(_ => true)) .WithServiceBusMessageHandler( - messageContextFilter: context => context != null, - messageBodySerializerImplementationFactory: serviceProvider => - { - var logger = serviceProvider.GetService>(); - return new OrderBatchMessageBodySerializer(logger); - }, - messageBodyFilter: message => message.Orders.Length == 1); + opt => opt.AddMessageContextFilter(context => context != null) + .AddMessageBodyFilter(message => message.Orders.Length == 1) + .AddMessageBodySerializer(serviceProvider => + { + var logger = serviceProvider.GetService>(); + return new OrderBatchMessageBodySerializer(logger); + })); }); } @@ -68,10 +68,16 @@ public async Task ServiceBusQueueMessagePumpWithContextAndBodyFiltering_RoutesSe // Arrange var options = new WorkerOptions(); options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = true) - .WithServiceBusMessageHandler(context => context.Properties.ContainsKey("NotExisting"), _ => false) - .WithServiceBusMessageHandler( - context => context.Properties["Topic"].ToString() == "Orders", - body => body.Id != null); + .WithServiceBusMessageHandler(opt => + { + opt.AddMessageContextFilter(context => context.Properties.ContainsKey("NotExisting")) + .AddMessageBodyFilter(_ => false); + }) + .WithServiceBusMessageHandler(opt => + { + opt.AddMessageContextFilter(context => context.Properties["Topic"].ToString() == "Orders") + .AddMessageBodyFilter(body => body.Id != null); + }); ServiceBusMessage message = CreateOrderServiceBusMessageForW3C(); message.ApplicationProperties["Topic"] = "Orders"; @@ -90,8 +96,14 @@ public async Task ServiceBusTopicMessagePumpWithContextFiltering_RoutesServiceBu // Arrange var options = new WorkerOptions(); options.AddServiceBusTopicMessagePumpUsingManagedIdentity(TopicName, HostName) - .WithServiceBusMessageHandler(context => context.Properties.TryGetValue("Topic", out object value) && value.ToString() == "Customers") - .WithServiceBusMessageHandler(context => context.Properties.TryGetValue("Topic", out object value) && value.ToString() == "Orders") + .WithServiceBusMessageHandler(opt => + { + opt.AddMessageContextFilter(context => context.Properties.TryGetValue("Topic", out object value) && value.ToString() == "Customers"); + }) + .WithServiceBusMessageHandler(opt => + { + opt.AddMessageContextFilter(context => context.Properties.TryGetValue("Topic", out object value) && value.ToString() == "Orders"); + }) .WithMessageHandler((AzureServiceBusMessageContext _) => false); ServiceBusMessage message = CreateOrderServiceBusMessageForW3C(); @@ -112,11 +124,11 @@ await TestServiceBusMessageHandlingAsync(Queue, options => { options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = true) .WithServiceBusMessageHandler( - messageBodySerializerImplementationFactory: serviceProvider => + opt => opt.AddMessageBodySerializer(serviceProvider => { var logger = serviceProvider.GetService>(); return new OrderBatchMessageBodySerializer(logger); - }); + })); }); } @@ -191,7 +203,7 @@ public async Task ServiceBusMessagePumpWithFallback_PublishServiceBusMessage_Mes await TestServiceBusMessageHandlingAsync(Queue, options => { options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = true) - .WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => false) + .WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => false)) .WithFallbackMessageHandler(); }); } @@ -202,7 +214,7 @@ public async Task ServiceBusMessagePumpWithServiceBusFallback_PublishServiceBusM await TestServiceBusMessageHandlingAsync(Queue, options => { options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = true) - .WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => false) + .WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => false)) .WithServiceBusFallbackMessageHandler(); }); } diff --git a/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.ServiceBusTests.cs b/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.ServiceBusTests.cs index 42603ca0..00e153bf 100644 --- a/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.ServiceBusTests.cs +++ b/src/Arcus.Messaging.Tests.Integration/MessagePump/ServiceBusMessagePump.ServiceBusTests.cs @@ -1,6 +1,6 @@ -using System; - using System.Linq; - using System.Threading.Tasks; +using System; +using System.Linq; +using System.Threading.Tasks; using Arcus.Messaging.Abstractions.ServiceBus; using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; using Arcus.Messaging.Pumps.ServiceBus; @@ -14,7 +14,6 @@ using Azure.Messaging.ServiceBus; using Azure.Messaging.ServiceBus.Administration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Xunit; using static Arcus.Messaging.Tests.Integration.MessagePump.ServiceBus.DiskMessageEventConsumer; using static Microsoft.Extensions.Logging.ServiceBusEntityType; @@ -29,7 +28,7 @@ public async Task ServiceBusQueueMessagePumpWithServiceBusDeadLetter_PublishServ await TestServiceBusQueueDeadLetteredMessageAsync(options => { options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = false) - .WithServiceBusMessageHandler(context => context.Properties["Topic"].ToString() == "Customers") + .WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(context => context.Properties["Topic"].ToString() == "Customers")) .WithServiceBusMessageHandler() .WithMessageHandler((AzureServiceBusMessageContext _) => false); }); @@ -41,7 +40,7 @@ public async Task ServiceBusQueueMessagePumpWithServiceBusDeadLetterOnFallback_P await TestServiceBusQueueDeadLetteredMessageAsync(options => { options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = false) - .WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => true) + .WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => true)) .WithServiceBusFallbackMessageHandler(); }); } @@ -68,7 +67,7 @@ await TestServiceBusQueueAbandonMessageAsync(options => { options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName) .WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => false) - .WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => true); + .WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => true)); }); } @@ -90,7 +89,7 @@ private async Task TestServiceBusQueueAbandonMessageAsync(Action configureOptions(options); ServiceBusMessage message = CreateOrderServiceBusMessageForW3C(); - + // Act await TestServiceBusMessageHandlingAsync(options, Queue, message, async () => { @@ -108,9 +107,9 @@ public async Task ServiceBusQueueMessagePumpWithCustomCompleteOnFallback_Publish options.AddServiceBusQueueMessagePumpUsingManagedIdentity(QueueName, HostName, configureMessagePump: opt => opt.AutoComplete = false) .WithServiceBusMessageHandler() .WithServiceBusFallbackMessageHandler(); - + ServiceBusMessage message = CreateOrderServiceBusMessageForW3C(); - + // Act await TestServiceBusMessageHandlingAsync(options, Queue, message, async () => { @@ -204,7 +203,7 @@ public async Task ServiceBusTopicMessagePumpWithMultipleMessages_PublishesServic options.AddServiceBusTopicMessagePumpUsingManagedIdentity(TopicName, HostName) .WithServiceBusMessageHandler(); - ServiceBusMessage[] messages = + ServiceBusMessage[] messages = Bogus.Make(50, () => CreateOrderServiceBusMessageForW3C()).ToArray(); await using var worker = await Worker.StartNewAsync(options); @@ -226,7 +225,7 @@ public async Task ServiceBusMessagePump_WithServiceBusDeadLetterDuringProcessing { await TestServiceBusMessageHandlingAsync(pump => { - pump.WithServiceBusMessageHandler(context => context.Properties["Topic"].ToString() == "Customers") + pump.WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(context => context.Properties["Topic"].ToString() == "Customers")) .WithServiceBusMessageHandler() .WithMessageHandler((AzureServiceBusMessageContext _) => false); }, @@ -242,7 +241,7 @@ public async Task ServiceBusMessagePump_WithServiceBusDeadLetterOnFallback_ThenM await TestServiceBusMessageHandlingAsync( pump => { - pump.WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => true) + pump.WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => true)) .WithServiceBusFallbackMessageHandler(); }, async (message, consumer) => @@ -257,8 +256,8 @@ public async Task ServiceBusMessagePump_WithServiceBusAbandonInProcessing_ThenMe await TestServiceBusMessageHandlingAsync( pump => { - pump.WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => false) - .WithServiceBusMessageHandler((AzureServiceBusMessageContext _) => true); + pump.WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => false)) + .WithServiceBusMessageHandler(opt => opt.AddMessageContextFilter(_ => true)); }, async (message, consumer) => { @@ -314,7 +313,7 @@ await TestServiceBusMessageHandlingAsync( pump => { pump.WithServiceBusMessageHandler(); - }, + }, async (message, consumer) => { await consumer.AssertAbandonMessageAsync(message.MessageId); @@ -401,14 +400,14 @@ public async Task ServiceBusTopicMessagePump_WithNoneTopicSubscription_DoesNotCr var subscriptionName = $"Subscription-{Guid.NewGuid():N}"; options.AddServiceBusTopicMessagePumpUsingManagedIdentity( TopicName, - subscriptionName, - HostName, + subscriptionName, + HostName, configureMessagePump: opt => opt.TopicSubscription = topicSubscription) .WithServiceBusMessageHandler(); - + // Act await using var worker = await Worker.StartNewAsync(options); - + // Assert ServiceBusAdministrationClient client = _serviceBusConfig.GetAdminClient(); Response subscriptionExistsResponse = await client.SubscriptionExistsAsync(TopicName, subscriptionName); @@ -422,7 +421,7 @@ await TestServiceBusMessageHandlingAsync(Topic, options => { options.AddServiceBusTopicMessagePumpUsingManagedIdentity( TopicName, - subscriptionName: "Test-Receive-All-Topic-Only-with-an-azure-servicebus-topic-subscription-name-over-50-characters", + subscriptionName: "Test-Receive-All-Topic-Only-with-an-azure-servicebus-topic-subscription-name-over-50-characters", HostName, configureMessagePump: opt => { diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/.gitignore b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/.gitignore deleted file mode 100644 index ff5b00c5..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/.gitignore +++ /dev/null @@ -1,264 +0,0 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# Azure Functions localsettings file -local.settings.json - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -#*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess.csproj b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess.csproj deleted file mode 100644 index 96ec3ab9..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - net8.0 - v4 - /home/site/wwwroot - Linux - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - Never - - - diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Dockerfile b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Dockerfile deleted file mode 100644 index 2749935f..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0.100-alpine3.18 AS publish -WORKDIR /src -COPY ["Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess.csproj", "Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/"] -RUN dotnet restore "Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess.csproj" -COPY . . -RUN dotnet publish "Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess.csproj" -c Release -o /app/publish - -FROM mcr.microsoft.com/azure-functions/dotnet:4 AS runtime -WORKDIR /home/site/wwwroot -EXPOSE 80 -COPY --from=publish /app/publish . -ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ - AzureFunctionsJobHost__Logging__Console__IsEnabled=true \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/OrderFunction.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/OrderFunction.cs deleted file mode 100644 index 60b23088..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/OrderFunction.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.EventHubs; -using Arcus.Messaging.Abstractions.EventHubs.MessageHandling; -using Arcus.Messaging.AzureFunctions.EventHubs; -using Azure.Messaging.EventHubs; -using Microsoft.Azure.WebJobs; -using Microsoft.Extensions.Logging; - -namespace Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess -{ - public class OrderFunction - { - private readonly string _jobId = Guid.NewGuid().ToString(); - private readonly IAzureEventHubsMessageRouter _messageRouter; - private readonly AzureFunctionsInProcessMessageCorrelation _messageCorrelation; - - /// - /// Initializes a new instance of the class. - /// - public OrderFunction( - IAzureEventHubsMessageRouter messageRouter, - AzureFunctionsInProcessMessageCorrelation messageCorrelation) - { - _messageRouter = messageRouter; - _messageCorrelation = messageCorrelation; - } - - [FunctionName("orders")] - public async Task Run( - [EventHubTrigger("orders-az-func-inprocess-docker", Connection = "EventHubsConnectionString")] EventData[] events, - ILogger log, - CancellationToken cancellation) - { - log.LogInformation("Processing first Azure EventHubs message: {MessageId}", events[0].MessageId); - - foreach (EventData eventData in events) - { - AzureEventHubsMessageContext messageContext = eventData.GetMessageContext("", "", "$Default", _jobId); - using (MessageCorrelationResult result = _messageCorrelation.CorrelateMessage(eventData)) - { - await _messageRouter.RouteMessageAsync(eventData, messageContext, result.CorrelationInfo, cancellation); - } - } - } - } -} diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Properties/serviceDependencies.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Properties/serviceDependencies.json deleted file mode 100644 index c264e8ca..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Properties/serviceDependencies.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "dependencies": { - "appInsights1": { - "type": "appInsights" - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Startup.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Startup.cs deleted file mode 100644 index 6a4ced35..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/Startup.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using Arcus.EventGrid.Publishing; -using Arcus.Messaging.Tests.Core.Messages.v1; -using Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess; -using Arcus.Messaging.Tests.Workers.MessageHandlers; -using Azure; -using Microsoft.Azure.Functions.Extensions.DependencyInjection; -using Microsoft.Extensions.Azure; -using Microsoft.Extensions.DependencyInjection; - -[assembly: FunctionsStartup(typeof(Startup))] - -namespace Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess -{ - public class Startup : FunctionsStartup - { - /// - /// This method gets called by the runtime. Use this method to add services to the container. - /// - /// The instance to build the registered services inside the functions app. - public override void Configure(IFunctionsHostBuilder builder) - { - builder.Services.AddAzureClients(clients => - { - var eventGridTopic = Environment.GetEnvironmentVariable("EVENTGRID_TOPIC_URI"); - var eventGridKey = Environment.GetEnvironmentVariable("EVENTGRID_AUTH_KEY"); - clients.AddEventGridPublisherClient(new Uri(eventGridTopic), new AzureKeyCredential(eventGridKey)); - }); - - builder.AddEventHubsMessageRouting() - .WithEventHubsMessageHandler(); - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/host.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/host.json deleted file mode 100644 index beb2e402..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.InProcess/host.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/.gitignore b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/.gitignore deleted file mode 100644 index ff5b00c5..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/.gitignore +++ /dev/null @@ -1,264 +0,0 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# Azure Functions localsettings file -local.settings.json - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -#*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.csproj b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.csproj deleted file mode 100644 index 663e533b..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - net8.0 - v4 - Exe - /home/site/wwwroot - Linux - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - Never - - - - - - \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Dockerfile b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Dockerfile deleted file mode 100644 index 2b75321f..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. - -FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base -WORKDIR /home/site/wwwroot -EXPOSE 80 - -FROM mcr.microsoft.com/dotnet/sdk:8.0.100-alpine3.18 AS build -WORKDIR /src -COPY ["Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.csproj", "Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/"] -RUN dotnet restore "Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.csproj" -COPY . . -WORKDIR "/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs" -RUN dotnet build "Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /home/site/wwwroot -COPY --from=publish /app/publish . -ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ - AzureFunctionsJobHost__Logging__Console__IsEnabled=true \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/OrderFunction.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/OrderFunction.cs deleted file mode 100644 index 466ff16e..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/OrderFunction.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.EventHubs; -using Arcus.Messaging.Abstractions.EventHubs.MessageHandling; -using Azure.Messaging.EventHubs; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; - -namespace Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs -{ - public class OrderFunction - { - private readonly IAzureEventHubsMessageRouter _messageRouter; - private readonly string _jobId = Guid.NewGuid().ToString(); - private readonly ILogger _logger; - - public OrderFunction( - IAzureEventHubsMessageRouter messageRouter, - ILoggerFactory loggerFactory) - { - _messageRouter = messageRouter; - _logger = loggerFactory.CreateLogger(); - } - - [Function("orders")] - public async Task Run( - [EventHubTrigger("orders-az-func-docker", Connection = "EventHubsConnectionString")] string[] messages, - Dictionary[] propertiesArray, - FunctionContext executionContext) - { - _logger.LogInformation($"First Event Hubs triggered message: {messages[0]}"); - - for (var i = 0; i < messages.Length; i++) - { - string message = messages[i]; - Dictionary properties = propertiesArray[i]; - - EventData eventData = CreateEventData(message, properties); - AzureEventHubsMessageContext messageContext = eventData.GetMessageContext("", "$Default", "", _jobId); - - using (MessageCorrelationResult result = executionContext.GetCorrelationInfo(properties)) - { - await _messageRouter.RouteMessageAsync(eventData, messageContext, result.CorrelationInfo, CancellationToken.None); - } - } - } - - private static EventData CreateEventData(string message, IDictionary properties) - { - var data = new EventData(message); - foreach (KeyValuePair property in properties) - { - data.Properties.Add(property.Key, property.Value.ToString()); - } - - return data; - } - } -} diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Program.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Program.cs deleted file mode 100644 index 255032cd..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Program.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using Arcus.EventGrid.Publishing; -using Arcus.Messaging.Tests.Core.Messages.v1; -using Arcus.Messaging.Tests.Workers.MessageHandlers; -using Azure; -using Microsoft.Extensions.Azure; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -var host = new HostBuilder() - .ConfigureFunctionsWorkerDefaults(builder => - { - builder.Services.AddAzureClients(clients => - { - var eventGridTopic = Environment.GetEnvironmentVariable("EVENTGRID_TOPIC_URI"); - var eventGridKey = Environment.GetEnvironmentVariable("EVENTGRID_AUTH_KEY"); - clients.AddEventGridPublisherClient(new Uri(eventGridTopic), new AzureKeyCredential(eventGridKey)); - }); - - builder.Services.AddEventHubsMessageRouting() - .WithEventHubsMessageHandler(); - }) - .Build(); - -host.Run(); diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Properties/serviceDependencies.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Properties/serviceDependencies.json deleted file mode 100644 index c264e8ca..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/Properties/serviceDependencies.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "dependencies": { - "appInsights1": { - "type": "appInsights" - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/host.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/host.json deleted file mode 100644 index beb2e402..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/host.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/local.settings.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/local.settings.json deleted file mode 100644 index 30386e36..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.EventHubs/local.settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "IsEncrypted": false, - "Values": { - "AzureWebJobsStorage": "", - "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/.dockerignore b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/.dockerignore deleted file mode 100644 index 1927772b..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -local.settings.json \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/.gitignore b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/.gitignore deleted file mode 100644 index ff5b00c5..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/.gitignore +++ /dev/null @@ -1,264 +0,0 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# Azure Functions localsettings file -local.settings.json - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -#*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue.csproj b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue.csproj deleted file mode 100644 index b1fc95ba..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue.csproj +++ /dev/null @@ -1,31 +0,0 @@ - - - net8.0 - v4 - Linux - /home/site/wwwroot - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - Never - - - diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Dockerfile b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Dockerfile deleted file mode 100644 index 40ef350e..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0.100-alpine3.18 AS publish -WORKDIR /src -COPY ["Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue.csproj", "Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/"] -RUN dotnet restore "Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue.csproj" -COPY . . -RUN dotnet publish "Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue.csproj" -c Release -o /app/publish - -FROM mcr.microsoft.com/azure-functions/dotnet:4 AS runtime -WORKDIR /home/site/wwwroot -EXPOSE 80 -COPY --from=publish /app/publish . -ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ - AzureFunctionsJobHost__Logging__Console__IsEnabled=true \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Functions/OrderProcessingFunction.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Functions/OrderProcessingFunction.cs deleted file mode 100644 index 8136b799..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Functions/OrderProcessingFunction.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.ServiceBus; -using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; -using Arcus.Messaging.AzureFunctions.ServiceBus; -using Azure.Messaging.ServiceBus; -using Microsoft.Azure.WebJobs; -using Microsoft.Extensions.Logging; - -namespace Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue.Functions -{ - public class OrderProcessingFunction - { - private readonly IAzureServiceBusMessageRouter _messageRouter; - private readonly AzureFunctionsInProcessMessageCorrelation _messageCorrelation; - private readonly string _jobId; - - /// - /// Initializes a new instance of the class. - /// - public OrderProcessingFunction( - IAzureServiceBusMessageRouter messageRouter, - AzureFunctionsInProcessMessageCorrelation messageCorrelation) - { - _messageRouter = messageRouter; - _messageCorrelation = messageCorrelation; - _jobId = Guid.NewGuid().ToString(); - } - - [FunctionName("order-processing")] - public async Task Run( - [ServiceBusTrigger("docker-az-func-queue", Connection = "ARCUS_SERVICEBUS_CONNECTIONSTRING")] ServiceBusReceivedMessage message, - ILogger log, - CancellationToken cancellationToken) - { - log.LogInformation($"C# ServiceBus queue trigger function processed message: {message.MessageId}"); - - AzureServiceBusMessageContext context = message.GetMessageContext(_jobId); - using (MessageCorrelationResult result = _messageCorrelation.CorrelateMessage(message)) - { - await _messageRouter.RouteMessageAsync(message, context, result.CorrelationInfo, cancellationToken); - } - } - } -} diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Properties/serviceDependencies.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Properties/serviceDependencies.json deleted file mode 100644 index df4dcc9d..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Properties/serviceDependencies.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { - "appInsights1": { - "type": "appInsights" - }, - "storage1": { - "type": "storage", - "connectionId": "AzureWebJobsStorage" - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Startup.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Startup.cs deleted file mode 100644 index 20ce8710..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/Startup.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using Arcus.EventGrid.Publishing; -using Arcus.Messaging.Tests.Core.Messages.v1; -using Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue; -using Arcus.Messaging.Tests.Workers.MessageHandlers; -using Azure; -using Microsoft.Azure.Functions.Extensions.DependencyInjection; -using Microsoft.Extensions.Azure; -using Microsoft.Extensions.DependencyInjection; - -[assembly: FunctionsStartup(typeof(Startup))] - -namespace Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue -{ - public class Startup : FunctionsStartup - { - /// - /// This method gets called by the runtime. Use this method to add services to the container. - /// - /// The instance to build the registered services inside the functions app. - public override void Configure(IFunctionsHostBuilder builder) - { - builder.Services.AddAzureClients(clients => - { - var eventGridTopic = Environment.GetEnvironmentVariable("ARCUS_EVENTGRID_TOPIC_URI"); - var eventGridKey = Environment.GetEnvironmentVariable("ARCUS_EVENTGRID_AUTH_KEY"); - clients.AddEventGridPublisherClient(new Uri(eventGridTopic), new AzureKeyCredential(eventGridKey)); - }); - - builder.AddServiceBusMessageRouting() - .WithServiceBusMessageHandler(); - } - } -} diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/host.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/host.json deleted file mode 100644 index bb3b8dad..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/host.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingExcludedTypes": "Request", - "samplingSettings": { - "isEnabled": true - } - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/local.settings.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/local.settings.json deleted file mode 100644 index 7de9b605..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Queue/local.settings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "IsEncrypted": false, - "Values": { - "AzureWebJobsStorage": "UseDevelopmentStorage=true", - "FUNCTIONS_WORKER_RUNTIME": "dotnet", - "SERVICEBUS_CONNECTIONSTRING": "#{Arcus.ServiceBus.Docker.NamespaceConnectionString}#", - "ARCUS_EVENTGRID_TOPIC_URI": "#{Arcus.TestInfra.EventGrid.Topic.Uri}#", - "ARCUS_EVENTGRID_AUTH_KEY": "#{Arcus.TestInfra.EventGrid.Auth.Key}#" - } -} diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/.gitignore b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/.gitignore deleted file mode 100644 index ff5b00c5..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/.gitignore +++ /dev/null @@ -1,264 +0,0 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# Azure Functions localsettings file -local.settings.json - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -#*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic.csproj b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic.csproj deleted file mode 100644 index f3bde973..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic.csproj +++ /dev/null @@ -1,36 +0,0 @@ - - - net8.0 - v4 - Exe - enable - enable - /home/site/wwwroot - Linux - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - Never - - - - - - \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Dockerfile b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Dockerfile deleted file mode 100644 index 9305e5bc..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. - -FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base -WORKDIR /home/site/wwwroot -EXPOSE 80 - -FROM mcr.microsoft.com/dotnet/sdk:8.0.100-alpine3.18 AS build -WORKDIR /src -COPY ["Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic.csproj", "Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/"] -RUN dotnet restore "Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic.csproj" -COPY . . -WORKDIR "/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic" -RUN dotnet build "Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /home/site/wwwroot -COPY --from=publish /app/publish . -ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ - AzureFunctionsJobHost__Logging__Console__IsEnabled=true \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/OrderProcessingFunction.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/OrderProcessingFunction.cs deleted file mode 100644 index 1ef4dfca..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/OrderProcessingFunction.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.ServiceBus; -using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; -using Azure.Messaging.ServiceBus; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; - -namespace Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic -{ - public class OrderProcessingFunction - { - private readonly IAzureServiceBusMessageRouter _messageRouter; - private readonly string _jobId; - private readonly ILogger _logger; - - public OrderProcessingFunction( - IAzureServiceBusMessageRouter messageRouter, - ILoggerFactory loggerFactory) - { - _messageRouter = messageRouter; - _jobId = Guid.NewGuid().ToString(); - _logger = loggerFactory.CreateLogger(); - } - - [Function("order-processing")] - public async Task Run( - [ServiceBusTrigger("docker-az-func-topic", "TestSubscription", Connection = "ARCUS_SERVICEBUS_CONNECTIONSTRING")] ServiceBusReceivedMessage message, - FunctionContext executionContext) - { - _logger.LogInformation("C# ServiceBus topic trigger function processed message: {MessageId}", message.MessageId); - - AzureServiceBusMessageContext messageContext = message.GetMessageContext(_jobId); - using (MessageCorrelationResult result = executionContext.GetCorrelationInfo()) - { - await _messageRouter.RouteMessageAsync(message, messageContext, result.CorrelationInfo, CancellationToken.None); - } - } - } -} diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Program.cs b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Program.cs deleted file mode 100644 index caaa7e5e..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Program.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Arcus.EventGrid.Publishing; -using Arcus.Messaging.Tests.Core.Messages.v1; -using Arcus.Messaging.Tests.Workers.MessageHandlers; -using Azure; -using Microsoft.Extensions.Azure; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -var host = new HostBuilder() - .ConfigureFunctionsWorkerDefaults(builder => - { - builder.Services.AddAzureClients(clients => - { - var eventGridTopic = Environment.GetEnvironmentVariable("ARCUS_EVENTGRID_TOPIC_URI"); - var eventGridKey = Environment.GetEnvironmentVariable("ARCUS_EVENTGRID_AUTH_KEY"); - clients.AddEventGridPublisherClient(new Uri(eventGridTopic), new AzureKeyCredential(eventGridKey)); - }); - - builder.Services.AddServiceBusMessageRouting() - .WithServiceBusMessageHandler(); - }) - .Build(); - -host.Run(); diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Properties/serviceDependencies.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Properties/serviceDependencies.json deleted file mode 100644 index c264e8ca..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/Properties/serviceDependencies.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "dependencies": { - "appInsights1": { - "type": "appInsights" - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/host.json b/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/host.json deleted file mode 100644 index beb2e402..00000000 --- a/src/Arcus.Messaging.Tests.Runtimes.AzureFunction.ServiceBus.Topic/host.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Unit/Arcus.Messaging.Tests.Unit.csproj b/src/Arcus.Messaging.Tests.Unit/Arcus.Messaging.Tests.Unit.csproj index a12565ac..353968fe 100644 --- a/src/Arcus.Messaging.Tests.Unit/Arcus.Messaging.Tests.Unit.csproj +++ b/src/Arcus.Messaging.Tests.Unit/Arcus.Messaging.Tests.Unit.csproj @@ -18,8 +18,6 @@ - - diff --git a/src/Arcus.Messaging.Tests.Unit/EventHubs/AzureFunctions/FunctionContextExtensions.cs b/src/Arcus.Messaging.Tests.Unit/EventHubs/AzureFunctions/FunctionContextExtensions.cs deleted file mode 100644 index 9524480f..00000000 --- a/src/Arcus.Messaging.Tests.Unit/EventHubs/AzureFunctions/FunctionContextExtensions.cs +++ /dev/null @@ -1,201 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Text.Json; -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.MessageHandling; -using Arcus.Messaging.Tests.Core.Correlation; -using Microsoft.ApplicationInsights; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.DependencyInjection; -using Moq; -using Xunit; - -namespace Arcus.Messaging.Tests.Unit.EventHubs.AzureFunctions -{ - public class FunctionContextExtensions - { - [Fact] - public void GetCorrelationInfoForW3C_WithoutTraceParent_GetsNewParent() - { - // Arrange - var properties = new Dictionary(); - FunctionContext context = CreateFunctionContext( - configureServices: services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = context.GetCorrelationInfo(properties)) - { - // Assert - Assert.NotNull(result.CorrelationInfo); - Assert.NotNull(result.CorrelationInfo.OperationId); - Assert.NotNull(result.CorrelationInfo.TransactionId); - Assert.NotNull(result.CorrelationInfo.OperationParentId); - } - } - - [Fact] - public void GetCorrelationInfoForW3C_WithTraceParent_GetsExistingParent() - { - // Arrange - var traceParent = TraceParent.Generate(); - var properties = new Dictionary - { - ["Diagnostic-Id"] = JsonSerializer.SerializeToElement(traceParent.DiagnosticId) - }; - FunctionContext context = CreateFunctionContext( - configureServices: services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = context.GetCorrelationInfo(properties)) - { - // Assert - Assert.NotNull(result.CorrelationInfo); - Assert.NotNull(result.CorrelationInfo.OperationId); - Assert.Equal(traceParent.TransactionId, result.CorrelationInfo.TransactionId); - Assert.Equal(traceParent.OperationParentId, result.CorrelationInfo.OperationParentId); - } - } - - [Fact] - public void GetCorrelationInfoForHierarchical_WithoutCorrelationProperties_GetsNewValues() - { - // Arrange - string operationId = Guid.NewGuid().ToString(); - var properties = new Dictionary - { - ["CorrelationId"] = JsonSerializer.SerializeToElement(operationId) - }; - FunctionContext context = CreateFunctionContext( - configureServices: services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = - context.GetCorrelationInfo(properties, MessageCorrelationFormat.Hierarchical)) - { - // Assert - Assert.NotNull(result.CorrelationInfo); - Assert.Equal(operationId, result.CorrelationInfo.OperationId); - Assert.NotNull(result.CorrelationInfo.TransactionId); - Assert.Null(result.CorrelationInfo.OperationParentId); - } - } - - [Fact] - public void GetCorrelationInfoForHierarchical_WithTransactionId_GetTransactionId() - { - // Arrange - string operationId = Guid.NewGuid().ToString(); - string transactionId = Guid.NewGuid().ToString(); - var properties = new Dictionary - { - ["CorrelationId"] = JsonSerializer.SerializeToElement(operationId), - [PropertyNames.TransactionId] = JsonSerializer.SerializeToElement(transactionId) - }; - FunctionContext context = CreateFunctionContext( - configureServices: services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = - context.GetCorrelationInfo(properties, MessageCorrelationFormat.Hierarchical)) - { - // Assert - Assert.NotNull(result.CorrelationInfo); - Assert.Equal(operationId, result.CorrelationInfo.OperationId); - Assert.Equal(transactionId, result.CorrelationInfo.TransactionId); - Assert.Null(result.CorrelationInfo.OperationParentId); - } - } - - [Fact] - public void GetCorrelationInfoForHierarchical_WithOperationParentId_GetOperationParentId() - { - // Arrange - string operationId = Guid.NewGuid().ToString(); - string operationParentId = Guid.NewGuid().ToString(); - var properties = new Dictionary - { - ["CorrelationId"] = JsonSerializer.SerializeToElement(operationId), - [PropertyNames.OperationParentId] = JsonSerializer.SerializeToElement(operationParentId) - }; - FunctionContext context = CreateFunctionContext( - configureServices: services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = - context.GetCorrelationInfo(properties, MessageCorrelationFormat.Hierarchical)) - { - // Assert - Assert.NotNull(result.CorrelationInfo); - Assert.Equal(operationId, result.CorrelationInfo.OperationId); - Assert.NotNull(result.CorrelationInfo.TransactionId); - Assert.Equal(operationParentId, result.CorrelationInfo.OperationParentId); - } - } - - [Fact] - public void GetCorrelationInfoForHierarchical_WithOperationParentIdAndTransactionId_GetOperationParentIdAndTransactionId() - { - // Arrange - string operationId = Guid.NewGuid().ToString(); - string transactionId = Guid.NewGuid().ToString(); - string operationParentId = Guid.NewGuid().ToString(); - var properties = new Dictionary - { - ["CorrelationId"] = JsonSerializer.SerializeToElement(operationId), - [PropertyNames.TransactionId] = JsonSerializer.SerializeToElement(transactionId), - [PropertyNames.OperationParentId] = JsonSerializer.SerializeToElement(operationParentId) - }; - FunctionContext context = CreateFunctionContext( - configureServices: services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = - context.GetCorrelationInfo(properties, MessageCorrelationFormat.Hierarchical)) - { - // Assert - Assert.NotNull(result.CorrelationInfo); - Assert.Equal(operationId, result.CorrelationInfo.OperationId); - Assert.Equal(transactionId, result.CorrelationInfo.TransactionId); - Assert.Equal(operationParentId, result.CorrelationInfo.OperationParentId); - } - } - - [Fact] - public void GetCorrelationInfo_WithoutCorrelationId_GeneratesOperationId() - { - // Arrange - var properties = new Dictionary(); - FunctionContext context = CreateFunctionContext( - configureServices: services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = - context.GetCorrelationInfo(properties, MessageCorrelationFormat.Hierarchical)) - { - // Assert - Assert.NotNull(result.CorrelationInfo); - Assert.NotNull(result.CorrelationInfo.OperationId); - Assert.NotNull(result.CorrelationInfo.TransactionId); - Assert.Null(result.CorrelationInfo.OperationParentId); - } - } - - private FunctionContext CreateFunctionContext( - IDictionary bindingData = null, - Action configureServices = null) - { - var stubBindingContext = new Mock(); - stubBindingContext.Setup(s => s.BindingData).Returns(new ReadOnlyDictionary(bindingData ?? new Dictionary())); - - var stubFuncContext = new Mock(); - stubFuncContext.Setup(s => s.BindingContext).Returns(stubBindingContext.Object); - - var services = new ServiceCollection(); - configureServices?.Invoke(services); - stubFuncContext.Setup(s => s.InstanceServices).Returns(services.BuildServiceProvider()); - - return stubFuncContext.Object; - } - } -} diff --git a/src/Arcus.Messaging.Tests.Unit/EventHubs/AzureFunctions/IFunctionsHostBuilderExtensionsTests.cs b/src/Arcus.Messaging.Tests.Unit/EventHubs/AzureFunctions/IFunctionsHostBuilderExtensionsTests.cs deleted file mode 100644 index 9f6dfd4c..00000000 --- a/src/Arcus.Messaging.Tests.Unit/EventHubs/AzureFunctions/IFunctionsHostBuilderExtensionsTests.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Arcus.Messaging.Abstractions.EventHubs.MessageHandling; -using Arcus.Messaging.AzureFunctions.EventHubs; -using Arcus.Messaging.Tests.Unit.EventHubs.Fixture; -using Microsoft.Azure.Functions.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection; -using Moq; -using Xunit; - -namespace Arcus.Messaging.Tests.Unit.EventHubs.AzureFunctions -{ - // ReSharper disable once InconsistentNaming - public class IFunctionsHostBuilderExtensionsTests - { - [Fact] - public void AddEventHubsMessageRouting_WithoutOptions_RegistersRouter() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - - // Act - builder.Object.AddEventHubsMessageRouting(); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - Assert.NotNull(provider.GetService()); - Assert.NotNull(provider.GetService()); - } - - [Fact] - public void AddEventHubsRouting_WithOptions_RegistersRouter() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - - // Act - builder.Object.AddEventHubsMessageRouting(configureOptions: options => { }); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - Assert.NotNull(provider.GetService()); - Assert.NotNull(provider.GetService()); - } - - [Fact] - public void AddEventHubsRoutingT_WithoutOptions_RegistersRouter() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - - // Act - builder.Object.AddEventHubsMessageRouting( - serviceProvider => new TestAzureEventHubsMessageRouter(serviceProvider)); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - var messageRouter = provider.GetService(); - Assert.NotNull(messageRouter); - Assert.IsType(messageRouter); - Assert.NotNull(provider.GetService()); - } - - [Fact] - public void AddEventHubsRoutingT_WithOptions_RegistersRouter() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - - // Act - builder.Object.AddEventHubsMessageRouting( - (serviceProvider, options) => new TestAzureEventHubsMessageRouter(serviceProvider), - configureOptions: null); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - var messageRouter = provider.GetService(); - Assert.NotNull(messageRouter); - Assert.IsType(messageRouter); - Assert.NotNull(provider.GetService()); - } - } -} diff --git a/src/Arcus.Messaging.Tests.Unit/ServiceBus/AzureFunctions/FunctionContextExtensionsTests.cs b/src/Arcus.Messaging.Tests.Unit/ServiceBus/AzureFunctions/FunctionContextExtensionsTests.cs deleted file mode 100644 index 19569713..00000000 --- a/src/Arcus.Messaging.Tests.Unit/ServiceBus/AzureFunctions/FunctionContextExtensionsTests.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Arcus.Messaging.Abstractions; -using Arcus.Messaging.Abstractions.MessageHandling; -using Arcus.Messaging.Tests.Core.Correlation; -using Microsoft.ApplicationInsights; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.DependencyInjection; -using Moq; -using Newtonsoft.Json; -using Xunit; - -namespace Arcus.Messaging.Tests.Unit.ServiceBus.AzureFunctions -{ - public class FunctionContextExtensionsTests - { - [Fact] - public void GetCorrelationInfo_WithDiagnosticId_Succeeds() - { - // Arrange - var traceParent = TraceParent.Generate(); - FunctionContext context = CreateFunctionContext( - CreateBindingDataWithUserProperties(new Dictionary { ["Diagnostic-Id"] = traceParent.DiagnosticId }), - services => services.AddSingleton()); - - // Act - using (MessageCorrelationResult result = context.GetCorrelationInfo()) - { - // Assert - Assert.Equal(traceParent.TransactionId, result.CorrelationInfo.TransactionId); - Assert.Equal(traceParent.OperationParentId, result.CorrelationInfo.OperationParentId); - } - } - - [Fact] - public void GetCorrelationInfo_WithCustomCorrelationProperties_Succeeds() - { - // Arrange - var transactionId = Guid.NewGuid().ToString(); - string operationParentId = Guid.NewGuid().ToString(); - FunctionContext context = CreateFunctionContext( - CreateBindingDataWithUserProperties(new Dictionary - { - [PropertyNames.TransactionId] = transactionId, - [PropertyNames.OperationParentId] = operationParentId - })); - - // Act - using (MessageCorrelationResult result = context.GetCorrelationInfo(MessageCorrelationFormat.Hierarchical)) - { - // Assert - Assert.Equal(transactionId, result.CorrelationInfo.TransactionId); - Assert.Equal(operationParentId, result.CorrelationInfo.OperationParentId); - } - } - - [Theory] - [InlineData("My-Custom-Transaction", PropertyNames.OperationParentId)] - [InlineData(PropertyNames.TransactionId, "My-Custom-Parent")] - [InlineData("My-Custom-Transaction", "My-Custom-Parent")] - public void GetCorrelationInfo_WithCustomCorrelationPropertyNames_Succeeds( - string transactionIdPropertyName, - string operationParentIdPropertyName) - { - // Arrange - var transactionId = Guid.NewGuid().ToString(); - string operationParentId = Guid.NewGuid().ToString(); - FunctionContext context = CreateFunctionContext( - CreateBindingDataWithUserProperties(new Dictionary - { - [transactionIdPropertyName] = transactionId, - [operationParentIdPropertyName] = operationParentId - })); - - // Act - using (MessageCorrelationResult result = context.GetCorrelationInfo(transactionIdPropertyName, operationParentIdPropertyName)) - { - // Assert - Assert.Equal(transactionId, result.CorrelationInfo.TransactionId); - Assert.Equal(operationParentId, result.CorrelationInfo.OperationParentId); - } - } - - private static Dictionary CreateBindingDataWithUserProperties(Dictionary userProperties) - { - return new Dictionary - { - { "UserProperties", JsonConvert.SerializeObject(userProperties) } - }; - } - - [Fact] - public void GetCorrelationInfo_WithoutUserProperties_Fails() - { - // Arrange - FunctionContext context = CreateFunctionContext(bindingData: new Dictionary()); - - // Act / Assert - Assert.ThrowsAny(() => context.GetCorrelationInfo()); - } - - [Theory] - [InlineData(MessageCorrelationFormat.Hierarchical)] - [InlineData(MessageCorrelationFormat.W3C)] - public void GetCorrelationInfoWithFormat_WithoutUserProperties_Fails(MessageCorrelationFormat format) - { - // Arrange - FunctionContext context = CreateFunctionContext(bindingData: new Dictionary()); - - // Act / Assert - Assert.ThrowsAny(() => context.GetCorrelationInfo(format)); - } - - private FunctionContext CreateFunctionContext( - IDictionary bindingData, - Action configureServices = null) - { - var stubBindingContext = new Mock(); - stubBindingContext.Setup(s => s.BindingData).Returns(new ReadOnlyDictionary(bindingData)); - - var stubFuncContext = new Mock(); - stubFuncContext.Setup(s => s.BindingContext).Returns(stubBindingContext.Object); - - var services = new ServiceCollection(); - configureServices?.Invoke(services); - stubFuncContext.Setup(s => s.InstanceServices).Returns(services.BuildServiceProvider()); - - return stubFuncContext.Object; - } - } -} diff --git a/src/Arcus.Messaging.Tests.Unit/ServiceBus/AzureFunctions/IFunctionsHostBuilderExtensionsTests.cs b/src/Arcus.Messaging.Tests.Unit/ServiceBus/AzureFunctions/IFunctionsHostBuilderExtensionsTests.cs deleted file mode 100644 index 2d2861ea..00000000 --- a/src/Arcus.Messaging.Tests.Unit/ServiceBus/AzureFunctions/IFunctionsHostBuilderExtensionsTests.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; -using Arcus.Messaging.AzureFunctions.ServiceBus; -using Arcus.Messaging.Tests.Unit.Fixture; -using Microsoft.Azure.Functions.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging.Abstractions; -using Moq; -using Xunit; - -namespace Arcus.Messaging.Tests.Unit.ServiceBus.AzureFunctions -{ - // ReSharper disable once InconsistentNaming - public class IFunctionsHostBuilderExtensionsTests - { - [Fact] - public void AddServiceBusRouting_RegistersRouter_GetsRouterSucceeds() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - - // Act - builder.Object.AddServiceBusMessageRouting(); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - Assert.NotNull(provider.GetService()); - Assert.NotNull(provider.GetService()); - } - - [Fact] - public void AddServiceBusRoutingWithOptions_RegistersRouter_GetsRouterSucceeds() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - - // Act - builder.Object.AddServiceBusMessageRouting(configureOptions: options => { }); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - Assert.NotNull(provider.GetService()); - Assert.NotNull(provider.GetService()); - } - - [Fact] - public void AddServiceBusRoutingT_RegistersRouter_GetsRouterSucceeds() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - - // Act - builder.Object.AddServiceBusMessageRouting(serviceProvider => - { - return new TestAzureServiceBusMessageRouter(serviceProvider, NullLogger.Instance); - }); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - var router = provider.GetService(); - Assert.NotNull(router); - Assert.IsType(router); - Assert.NotNull(provider.GetService()); - } - - [Fact] - public void AddServiceBusRoutingTWithOptions_RegistersRouter_GetsRouterSucceeds() - { - // Arrange - var services = new ServiceCollection(); - var builder = new Mock(); - builder.Setup(b => b.Services).Returns(services); - var operationParentIdPropertyName = "MyOperationParentIdProperty"; - - // Act - builder.Object.AddServiceBusMessageRouting( - (serviceProvider, options) => - { - Assert.Equal(operationParentIdPropertyName, options.Correlation.OperationParentIdPropertyName); - return new TestAzureServiceBusMessageRouter(serviceProvider, NullLogger.Instance); - }, - options => options.Correlation.OperationParentIdPropertyName = operationParentIdPropertyName); - - // Assert - IServiceProvider provider = services.BuildServiceProvider(); - var router = provider.GetService(); - Assert.NotNull(router); - Assert.IsType(router); - Assert.NotNull(provider.GetService()); - } - } -} diff --git a/src/Arcus.Messaging.Tests.Workers.EventHubs/Arcus.Messaging.Tests.Workers.EventHubs.csproj b/src/Arcus.Messaging.Tests.Workers.EventHubs/Arcus.Messaging.Tests.Workers.EventHubs.csproj deleted file mode 100644 index e0d483e0..00000000 --- a/src/Arcus.Messaging.Tests.Workers.EventHubs/Arcus.Messaging.Tests.Workers.EventHubs.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - net8.0 - Exe - Linux - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Arcus.Messaging.Tests.Workers.EventHubs/Dockerfile b/src/Arcus.Messaging.Tests.Workers.EventHubs/Dockerfile deleted file mode 100644 index 405662f9..00000000 --- a/src/Arcus.Messaging.Tests.Workers.EventHubs/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM mcr.microsoft.com/dotnet/aspnet:8.0.2-alpine3.18 AS base -WORKDIR /app - -FROM mcr.microsoft.com/dotnet/sdk:8.0.100-alpine3.18 AS build -WORKDIR /src -COPY ["Arcus.Messaging.Tests.Workers.EventHubs/Arcus.Messaging.Tests.Workers.EventHubs.csproj", "Arcus.Messaging.Tests.Workers.EventHubs/"] -RUN dotnet restore "Arcus.Messaging.Tests.Workers.EventHubs/Arcus.Messaging.Tests.Workers.EventHubs.csproj" -COPY . . -WORKDIR "/src/Arcus.Messaging.Tests.Workers.EventHubs" -RUN dotnet build "Arcus.Messaging.Tests.Workers.EventHubs.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "Arcus.Messaging.Tests.Workers.EventHubs.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Arcus.Messaging.Tests.Workers.EventHubs.dll"] diff --git a/src/Arcus.Messaging.Tests.Workers.EventHubs/Program.cs b/src/Arcus.Messaging.Tests.Workers.EventHubs/Program.cs deleted file mode 100644 index 4caa188d..00000000 --- a/src/Arcus.Messaging.Tests.Workers.EventHubs/Program.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using Arcus.Messaging.Tests.Core.Messages.v1; -using Arcus.Messaging.Tests.Workers.MessageHandlers; -using Azure; -using Microsoft.Extensions.Azure; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Diagnostics.HealthChecks; -using Microsoft.Extensions.Hosting; - -namespace Arcus.Messaging.Tests.Workers.EventHubs -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args) - .Build() - .Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration(configuration => - { - configuration.AddCommandLine(args); - configuration.AddEnvironmentVariables(); - }) - .ConfigureSecretStore((config, stores) => - { - stores.AddConfiguration(config); - }) - .ConfigureServices((hostContext, services) => - { - services.AddLogging(); - services.AddAzureClients(clients => - { - var topicEndpoint = hostContext.Configuration.GetValue("EVENTGRID_TOPIC_URI"); - var authenticationKey = hostContext.Configuration.GetValue("EVENTGRID_AUTH_KEY"); - clients.AddEventGridPublisherClient(new Uri(topicEndpoint), new AzureKeyCredential(authenticationKey)); - }); - - var eventHubsName = hostContext.Configuration.GetValue("EVENTHUBS_NAME"); - var containerName = hostContext.Configuration.GetValue("BLOBSTORAGE_CONTAINERNAME"); - services.AddEventHubsMessagePump(eventHubsName, "EVENTHUBS_CONNECIONSTRING", containerName, "STORAGEACCOUNT_CONNECTIONSTRING") - .WithEventHubsMessageHandler(); - - services.AddTcpHealthProbes("ARCUS_HEALTH_PORT", builder => builder.AddCheck("sample", () => HealthCheckResult.Healthy())); - }); - } -} \ No newline at end of file diff --git a/src/Arcus.Messaging.Tests.Workers.ServiceBus/Fixture/MessageCorrelationInfoJsonConverter.cs b/src/Arcus.Messaging.Tests.Workers.ServiceBus/Fixture/MessageCorrelationInfoJsonConverter.cs index 466bd6e2..e8c9ab9b 100644 --- a/src/Arcus.Messaging.Tests.Workers.ServiceBus/Fixture/MessageCorrelationInfoJsonConverter.cs +++ b/src/Arcus.Messaging.Tests.Workers.ServiceBus/Fixture/MessageCorrelationInfoJsonConverter.cs @@ -5,19 +5,14 @@ namespace Arcus.Messaging.Tests.Workers.ServiceBus.Fixture { - public class MessageCorrelationInfoJsonConverter : JsonConverter + public class MessageCorrelationInfoJsonConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, MessageCorrelationInfo? value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { throw new NotImplementedException(); } - public override MessageCorrelationInfo? ReadJson( - JsonReader reader, - Type objectType, - MessageCorrelationInfo? existingValue, - bool hasExistingValue, - JsonSerializer serializer) + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject json = JObject.Load(reader); string operationId = json["OperationId"]?.ToString(); @@ -26,5 +21,10 @@ public override void WriteJson(JsonWriter writer, MessageCorrelationInfo? value, return new MessageCorrelationInfo(operationId, transactionId, operationParentId); } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(MessageCorrelationInfo); + } } } \ No newline at end of file diff --git a/src/Arcus.Messaging.sln b/src/Arcus.Messaging.sln index c79cb62d..506a893c 100644 --- a/src/Arcus.Messaging.sln +++ b/src/Arcus.Messaging.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.0.32126.317 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Tests.Integration", "Arcus.Messaging.Tests.Integration\Arcus.Messaging.Tests.Integration.csproj", "{ECBC0F80-31D0-452B-8EEA-B4BC2A9975A3}" EndProject -Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "Arcus.Messaging.Tests.Docker", "Arcus.Messaging.Tests.Docker.dcproj", "{49D85A35-F341-47A3-887F-68DEC06CEBCA}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{A1369CCD-42D1-43F6-98BC-D8EDA62C2B13}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Health", "Arcus.Messaging.Health\Arcus.Messaging.Health.csproj", "{1C456BF4-4947-4171-BF6F-80A9A511F740}" @@ -27,8 +25,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Tests.Core" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Abstractions.ServiceBus", "Arcus.Messaging.Abstractions.ServiceBus\Arcus.Messaging.Abstractions.ServiceBus.csproj", "{864C12DF-DE3D-421F-8687-EC3918FFB8BE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.AzureFunctions.ServiceBus", "Arcus.Messaging.AzureFunctions.ServiceBus\Arcus.Messaging.AzureFunctions.ServiceBus.csproj", "{7386C41A-6F27-42B7-BBC1-B6CB41200A68}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Pumps.EventHubs", "Arcus.Messaging.Pumps.EventHubs\Arcus.Messaging.Pumps.EventHubs.csproj", "{F5A14425-FEF5-425D-875C-2601C988E6FA}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Abstractions.EventHubs", "Arcus.Messaging.Abstractions.EventHubs\Arcus.Messaging.Abstractions.EventHubs.csproj", "{040DE2D5-0400-4B4A-A333-60C45CBB0204}" @@ -43,8 +39,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Tests.Worke EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.Tests.Workers.EventHubs.Core", "Arcus.Messaging.Tests.Workers.EventHubs.Core\Arcus.Messaging.Tests.Workers.EventHubs.Core.csproj", "{0D6C38A7-B684-43BA-9BCF-1EF4C1A943CD}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arcus.Messaging.AzureFunctions.EventHubs", "Arcus.Messaging.AzureFunctions.EventHubs\Arcus.Messaging.AzureFunctions.EventHubs.csproj", "{619AA74F-CDE4-48F6-B6E4-4B7C191CCB1B}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,10 +49,6 @@ Global {ECBC0F80-31D0-452B-8EEA-B4BC2A9975A3}.Debug|Any CPU.Build.0 = Debug|Any CPU {ECBC0F80-31D0-452B-8EEA-B4BC2A9975A3}.Release|Any CPU.ActiveCfg = Release|Any CPU {ECBC0F80-31D0-452B-8EEA-B4BC2A9975A3}.Release|Any CPU.Build.0 = Release|Any CPU - {49D85A35-F341-47A3-887F-68DEC06CEBCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {49D85A35-F341-47A3-887F-68DEC06CEBCA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {49D85A35-F341-47A3-887F-68DEC06CEBCA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {49D85A35-F341-47A3-887F-68DEC06CEBCA}.Release|Any CPU.Build.0 = Release|Any CPU {1C456BF4-4947-4171-BF6F-80A9A511F740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1C456BF4-4947-4171-BF6F-80A9A511F740}.Debug|Any CPU.Build.0 = Debug|Any CPU {1C456BF4-4947-4171-BF6F-80A9A511F740}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -95,10 +85,6 @@ Global {864C12DF-DE3D-421F-8687-EC3918FFB8BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {864C12DF-DE3D-421F-8687-EC3918FFB8BE}.Release|Any CPU.ActiveCfg = Release|Any CPU {864C12DF-DE3D-421F-8687-EC3918FFB8BE}.Release|Any CPU.Build.0 = Release|Any CPU - {7386C41A-6F27-42B7-BBC1-B6CB41200A68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7386C41A-6F27-42B7-BBC1-B6CB41200A68}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7386C41A-6F27-42B7-BBC1-B6CB41200A68}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7386C41A-6F27-42B7-BBC1-B6CB41200A68}.Release|Any CPU.Build.0 = Release|Any CPU {F5A14425-FEF5-425D-875C-2601C988E6FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F5A14425-FEF5-425D-875C-2601C988E6FA}.Debug|Any CPU.Build.0 = Debug|Any CPU {F5A14425-FEF5-425D-875C-2601C988E6FA}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -119,30 +105,23 @@ Global {0D6C38A7-B684-43BA-9BCF-1EF4C1A943CD}.Debug|Any CPU.Build.0 = Debug|Any CPU {0D6C38A7-B684-43BA-9BCF-1EF4C1A943CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {0D6C38A7-B684-43BA-9BCF-1EF4C1A943CD}.Release|Any CPU.Build.0 = Release|Any CPU - {619AA74F-CDE4-48F6-B6E4-4B7C191CCB1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {619AA74F-CDE4-48F6-B6E4-4B7C191CCB1B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {619AA74F-CDE4-48F6-B6E4-4B7C191CCB1B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {619AA74F-CDE4-48F6-B6E4-4B7C191CCB1B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {ECBC0F80-31D0-452B-8EEA-B4BC2A9975A3} = {A1369CCD-42D1-43F6-98BC-D8EDA62C2B13} - {49D85A35-F341-47A3-887F-68DEC06CEBCA} = {A1369CCD-42D1-43F6-98BC-D8EDA62C2B13} {B21CD154-120D-49C5-AC2B-AC3ABDE97641} = {2CD090E7-7306-49A0-9680-6ED78CFECAE1} {71FCD6E8-B586-4F4B-AA26-0C2F698B837E} = {2CD090E7-7306-49A0-9680-6ED78CFECAE1} {3C4C0426-284D-4279-8A68-B1B396EFEC57} = {A1369CCD-42D1-43F6-98BC-D8EDA62C2B13} {9EED9AD7-B69D-45D5-870F-D4F63A1C3495} = {A1369CCD-42D1-43F6-98BC-D8EDA62C2B13} {55DE6D12-4C54-4570-BDFA-00B0FFDE5AB6} = {A1369CCD-42D1-43F6-98BC-D8EDA62C2B13} {864C12DF-DE3D-421F-8687-EC3918FFB8BE} = {2CD090E7-7306-49A0-9680-6ED78CFECAE1} - {7386C41A-6F27-42B7-BBC1-B6CB41200A68} = {2CD090E7-7306-49A0-9680-6ED78CFECAE1} {F5A14425-FEF5-425D-875C-2601C988E6FA} = {31250C96-0F22-482F-B3D7-127898A28CF3} {040DE2D5-0400-4B4A-A333-60C45CBB0204} = {31250C96-0F22-482F-B3D7-127898A28CF3} {05EA4B3A-C619-44BB-88C4-F067FCCF83AA} = {31250C96-0F22-482F-B3D7-127898A28CF3} {F1B24FD4-099E-489D-B45D-A1A992CA5C3A} = {A1369CCD-42D1-43F6-98BC-D8EDA62C2B13} {0D6C38A7-B684-43BA-9BCF-1EF4C1A943CD} = {A1369CCD-42D1-43F6-98BC-D8EDA62C2B13} - {619AA74F-CDE4-48F6-B6E4-4B7C191CCB1B} = {31250C96-0F22-482F-B3D7-127898A28CF3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {066FD85A-3DDE-4615-B550-BF67ACCDAA51} diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml deleted file mode 100644 index ffec028c..00000000 --- a/src/docker-compose.override.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '3.4' - -services: - arcus.messaging.tests.workers.servicebus.queue: - environment: - - ARCUS_HEALTH_PORT=5001 - - ARCUS_SERVICEBUS_CONNECTIONSTRING= - - EVENTGRID_TOPIC_URI=https://arcus-event-grid-dev-we-integration-tests.westeurope-1.eventgrid.azure.net/api/events - - EVENTGRID_AUTH_KEY= - arcus.messaging.tests.workers.servicebus.topic: - environment: - - ARCUS_HEALTH_PORT=5001 - - ARCUS_SERVICEBUS_CONNECTIONSTRING=Endpoint= - - EVENTGRID_TOPIC_URI=https://arcus-event-grid-dev-we-integration-tests.westeurope-1.eventgrid.azure.net/api/events - - EVENTGRID_AUTH_KEY= \ No newline at end of file diff --git a/src/docker-compose.yml b/src/docker-compose.yml deleted file mode 100644 index 8a90e518..00000000 --- a/src/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '3.4' - -services: - arcus.messaging.tests.workers.servicebus.queue: - image: arcusazure/arcus.messaging.tests.workers.servicebus.queue - build: - context: . - dockerfile: Arcus.Messaging.Tests.Workers.ServiceBus.Queue/Dockerfile - arcus.messaging.tests.workers.servicebus.topic: - image: arcusazure/arcus.messaging.tests.workers.servicebus.topic - build: - context: . - dockerfile: Arcus.Messaging.Tests.Workers.ServiceBus.Topic/Dockerfile \ No newline at end of file