From 5aa5c59a27c547398281dca01059a8437312d342 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 7 May 2024 07:57:02 +0200 Subject: [PATCH 01/15] chore: upgrade templates to net8.0 --- ....Templates.AzureFunctions.EventHubs.csproj | 22 ++++++++--------- .../SensorReadingFunction.cs | 3 ++- ...Arcus.Templates.AzureFunctions.Http.csproj | 24 +++++++++---------- ...tes.AzureFunctions.ServiceBus.Queue.csproj | 20 ++++++++-------- ...tes.AzureFunctions.ServiceBus.Topic.csproj | 20 ++++++++-------- .../Arcus.Templates.EventHubs.csproj | 19 +++++++-------- .../Arcus.Templates.ServiceBus.Queue.csproj | 17 +++++++------ .../Arcus.Templates.ServiceBus.Topic.csproj | 17 +++++++------ .../Arcus.Templates.Tests.Integration.csproj | 18 +++++++------- .../AzureFunctionsEventHubsProject.cs | 2 +- .../Http/AzureFunctionsHttpProject.cs | 2 +- .../AzureFunctionsServiceBusProject.cs | 2 +- .../Fixture/TargetFramework.cs | 7 +----- .../Fixture/TemplateProject.cs | 3 +-- .../Fixture/TestConfig.cs | 2 +- .../WebApi/WebApiProject.cs | 2 +- .../TestServiceBusMessageEventConsumer.cs | 23 ------------------ .../Worker/WorkerProject.cs | 2 +- .../Arcus.Templates.WebApi.csproj | 23 +++++++++--------- src/Arcus.Templates.WebApi/Program.cs | 13 +++++----- 20 files changed, 104 insertions(+), 137 deletions(-) diff --git a/src/Arcus.Templates.AzureFunctions.EventHubs/Arcus.Templates.AzureFunctions.EventHubs.csproj b/src/Arcus.Templates.AzureFunctions.EventHubs/Arcus.Templates.AzureFunctions.EventHubs.csproj index 3f2a4619..0be4fbcd 100644 --- a/src/Arcus.Templates.AzureFunctions.EventHubs/Arcus.Templates.AzureFunctions.EventHubs.csproj +++ b/src/Arcus.Templates.AzureFunctions.EventHubs/Arcus.Templates.AzureFunctions.EventHubs.csproj @@ -1,6 +1,6 @@  - net6.0 + net8.0 Exe v4 Linux @@ -47,16 +47,16 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/src/Arcus.Templates.AzureFunctions.EventHubs/SensorReadingFunction.cs b/src/Arcus.Templates.AzureFunctions.EventHubs/SensorReadingFunction.cs index ad05934f..eae804cb 100644 --- a/src/Arcus.Templates.AzureFunctions.EventHubs/SensorReadingFunction.cs +++ b/src/Arcus.Templates.AzureFunctions.EventHubs/SensorReadingFunction.cs @@ -15,6 +15,7 @@ namespace Arcus.Templates.AzureFunctions.EventHubs { public class SensorReadingFunction { + private readonly string _jobId = Guid.NewGuid().ToString(); private readonly IAzureEventHubsMessageRouter _messageRouter; /// @@ -49,7 +50,7 @@ public async Task Run( Dictionary properties = propertiesArray[index]; EventData data = CreateEventData(message, properties); - AzureEventHubsMessageContext messageContext = data.GetMessageContext("sensor-reading.servicebus.windows.net", "sensors"); + AzureEventHubsMessageContext messageContext = data.GetMessageContext("sensor-reading.servicebus.windows.net", "sensors", "$Default", _jobId); using (MessageCorrelationResult result = executionContext.GetCorrelationInfo(properties)) { await _messageRouter.RouteMessageAsync(data, messageContext, result.CorrelationInfo, CancellationToken.None); diff --git a/src/Arcus.Templates.AzureFunctions.Http/Arcus.Templates.AzureFunctions.Http.csproj b/src/Arcus.Templates.AzureFunctions.Http/Arcus.Templates.AzureFunctions.Http.csproj index bffc1893..d91343ce 100644 --- a/src/Arcus.Templates.AzureFunctions.Http/Arcus.Templates.AzureFunctions.Http.csproj +++ b/src/Arcus.Templates.AzureFunctions.Http/Arcus.Templates.AzureFunctions.Http.csproj @@ -1,6 +1,6 @@  - net6.0 + net8.0 v4 Linux Exe @@ -46,7 +46,7 @@ - + @@ -61,16 +61,16 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Arcus.Templates.AzureFunctions.ServiceBus.Queue.csproj b/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Arcus.Templates.AzureFunctions.ServiceBus.Queue.csproj index fe096bde..3acf3fbf 100644 --- a/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Arcus.Templates.AzureFunctions.ServiceBus.Queue.csproj +++ b/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Arcus.Templates.AzureFunctions.ServiceBus.Queue.csproj @@ -1,6 +1,6 @@  - net6.0 + net8.0 Exe v4 Linux @@ -48,15 +48,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Arcus.Templates.AzureFunctions.ServiceBus.Topic.csproj b/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Arcus.Templates.AzureFunctions.ServiceBus.Topic.csproj index d2e81787..309e4aae 100644 --- a/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Arcus.Templates.AzureFunctions.ServiceBus.Topic.csproj +++ b/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Arcus.Templates.AzureFunctions.ServiceBus.Topic.csproj @@ -1,6 +1,6 @@  - net6.0 + net8.0 Exe v4 Linux @@ -47,15 +47,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Arcus.Templates.EventHubs/Arcus.Templates.EventHubs.csproj b/src/Arcus.Templates.EventHubs/Arcus.Templates.EventHubs.csproj index 04e6d0f8..7de08d0b 100644 --- a/src/Arcus.Templates.EventHubs/Arcus.Templates.EventHubs.csproj +++ b/src/Arcus.Templates.EventHubs/Arcus.Templates.EventHubs.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Linux Arcus @@ -49,15 +49,14 @@ - - - - - - - - - + + + + + + + + diff --git a/src/Arcus.Templates.ServiceBus.Queue/Arcus.Templates.ServiceBus.Queue.csproj b/src/Arcus.Templates.ServiceBus.Queue/Arcus.Templates.ServiceBus.Queue.csproj index e989dccd..08c63294 100644 --- a/src/Arcus.Templates.ServiceBus.Queue/Arcus.Templates.ServiceBus.Queue.csproj +++ b/src/Arcus.Templates.ServiceBus.Queue/Arcus.Templates.ServiceBus.Queue.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Linux Arcus @@ -49,14 +49,13 @@ - - - - - - - - + + + + + + + diff --git a/src/Arcus.Templates.ServiceBus.Topic/Arcus.Templates.ServiceBus.Topic.csproj b/src/Arcus.Templates.ServiceBus.Topic/Arcus.Templates.ServiceBus.Topic.csproj index 2a437d5a..524c4558 100644 --- a/src/Arcus.Templates.ServiceBus.Topic/Arcus.Templates.ServiceBus.Topic.csproj +++ b/src/Arcus.Templates.ServiceBus.Topic/Arcus.Templates.ServiceBus.Topic.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Linux Arcus @@ -49,14 +49,13 @@ - - - - - - - - + + + + + + + diff --git a/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj b/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj index 2e8c8efc..d9af13df 100644 --- a/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj +++ b/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false false @@ -29,14 +29,14 @@ - - - - - - - - + + + + + + + + diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs index f6e29a9b..2bb4e5df 100644 --- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs @@ -139,7 +139,7 @@ private async Task StartAsync() ApplicationInsightsConfig appInsightsConfig = Configuration.GetApplicationInsightsConfig(); Environment.SetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING", $"InstrumentationKey={appInsightsConfig.InstrumentationKey}"); - Run(Configuration.BuildConfiguration, TargetFramework.Net6_0); + Run(Configuration.BuildConfiguration, TargetFramework.Net8_0); await Messaging.StartAsync(); } catch diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs index f4d09118..1d60899a 100644 --- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs @@ -214,7 +214,7 @@ public async Task StartAsync() { try { - Run(Configuration.BuildConfiguration, TargetFramework.Net6_0); + Run(Configuration.BuildConfiguration, TargetFramework.Net8_0); await WaitUntilTriggerIsAvailableAsync(OrderFunctionEndpoint); } catch diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs index c066da38..8ef4f175 100644 --- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs @@ -169,7 +169,7 @@ private async Task StartAsync(ServiceBusEntityType entityType) Environment.SetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", instrumentationKey); Environment.SetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING", $"InstrumentationKey={instrumentationKey}"); - Run(Configuration.BuildConfiguration, TargetFramework.Net6_0); + Run(Configuration.BuildConfiguration, TargetFramework.Net8_0); await Messaging.StartAsync(); await WaitUntilTriggerIsAvailableAsync(Admin.Endpoint); } diff --git a/src/Arcus.Templates.Tests.Integration/Fixture/TargetFramework.cs b/src/Arcus.Templates.Tests.Integration/Fixture/TargetFramework.cs index ba4b02b7..f261181a 100644 --- a/src/Arcus.Templates.Tests.Integration/Fixture/TargetFramework.cs +++ b/src/Arcus.Templates.Tests.Integration/Fixture/TargetFramework.cs @@ -5,14 +5,9 @@ /// public enum TargetFramework { - /// - /// Sets the target framework of the project created from the templates to netcoreapp3.1. - /// - NetCoreApp31, - /// /// Sets the target framework of the project created from the templates to net6.0. /// - Net6_0 + Net8_0 } } diff --git a/src/Arcus.Templates.Tests.Integration/Fixture/TemplateProject.cs b/src/Arcus.Templates.Tests.Integration/Fixture/TemplateProject.cs index 41f508c7..aee75499 100644 --- a/src/Arcus.Templates.Tests.Integration/Fixture/TemplateProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Fixture/TemplateProject.cs @@ -334,8 +334,7 @@ protected static string GetTargetFrameworkIdentifier(TargetFramework targetFrame { switch (targetFramework) { - case TargetFramework.NetCoreApp31: return "netcoreapp3.1"; - case TargetFramework.Net6_0: return "net6.0"; + case TargetFramework.Net8_0: return "net8.0"; default: throw new ArgumentOutOfRangeException(nameof(targetFramework), targetFramework, "Unknown target framework specified for template project"); } diff --git a/src/Arcus.Templates.Tests.Integration/Fixture/TestConfig.cs b/src/Arcus.Templates.Tests.Integration/Fixture/TestConfig.cs index 729ee130..0762d31d 100644 --- a/src/Arcus.Templates.Tests.Integration/Fixture/TestConfig.cs +++ b/src/Arcus.Templates.Tests.Integration/Fixture/TestConfig.cs @@ -49,7 +49,7 @@ private TestConfig( /// The target framework in which the created project from the template should be build and run. public static TestConfig Create( BuildConfiguration buildConfiguration = BuildConfiguration.Debug, - TargetFramework targetFramework = TargetFramework.NetCoreApp31) + TargetFramework targetFramework = TargetFramework.Net8_0) { var configuration = new ConfigurationBuilder() .AddJsonFile(path: "appsettings.json", optional: true) diff --git a/src/Arcus.Templates.Tests.Integration/WebApi/WebApiProject.cs b/src/Arcus.Templates.Tests.Integration/WebApi/WebApiProject.cs index 06aa4214..e9bfade4 100644 --- a/src/Arcus.Templates.Tests.Integration/WebApi/WebApiProject.cs +++ b/src/Arcus.Templates.Tests.Integration/WebApi/WebApiProject.cs @@ -220,7 +220,7 @@ public async Task StartAsync() commandArguments = new[] { CommandArgument.CreateOpen("ARCUS_HTTP_PORT", _baseUrl.Port) }; } - Run(_configuration.BuildConfiguration, TargetFramework.Net6_0, commandArguments); + Run(_configuration.BuildConfiguration, TargetFramework.Net8_0, commandArguments); await WaitUntilWebProjectIsAvailable(_baseUrl.Port); } catch diff --git a/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs b/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs index 63ad4d3d..27458e81 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs @@ -1,11 +1,7 @@ using System; using System.Threading.Tasks; -using Arcus.EventGrid; -using Arcus.EventGrid.Contracts; -using Arcus.EventGrid.Parsers; using Arcus.EventGrid.Testing.Infrastructure.Hosts.ServiceBus; using Arcus.Templates.Tests.Integration.Fixture; -using Arcus.Templates.Tests.Integration.Worker.ServiceBus.Fixture; using Azure.Messaging; using GuardNet; using Microsoft.Extensions.Configuration; @@ -54,25 +50,6 @@ public static async Task StartNewAsync(TestC /// /// The ID to identity the produced event. /// Thrown when the is blank. - public OrderCreatedEventData ConsumeOrderEvent(string eventId) - { - Guard.NotNullOrWhitespace(eventId, nameof(eventId), "Requires a non-blank event ID to identity the produced event on the Azure Service Bus"); - - string receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(eventId, retryCount: 10); - Assert.NotEmpty(receivedEvent); - - EventBatch eventBatch = EventParser.Parse(receivedEvent); - Assert.NotNull(eventBatch); - Event @event = Assert.Single(eventBatch.Events); - Assert.NotNull(@event); - - var data = @event.Data.ToString(); - Assert.NotNull(data); - - var eventData = JsonConvert.DeserializeObject(data, new MessageCorrelationInfoJsonConverter()); - return eventData; - } - public TEventData ConsumeEvent(string eventId) { string receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(eventId, retryCount: 10); diff --git a/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs b/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs index a2589e93..53c92ca6 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs @@ -64,7 +64,7 @@ protected async Task StartAsync(WorkerProjectOptions options, params CommandArgu try { - Run(_configuration.BuildConfiguration, TargetFramework.Net6_0, commands); + Run(_configuration.BuildConfiguration, TargetFramework.Net8_0, commands); await WaitUntilWorkerProjectIsAvailableAsync(_healthPort); await Messaging.StartAsync(); } diff --git a/src/Arcus.Templates.WebApi/Arcus.Templates.WebApi.csproj b/src/Arcus.Templates.WebApi/Arcus.Templates.WebApi.csproj index 3d8f7ac7..5d064bb4 100644 --- a/src/Arcus.Templates.WebApi/Arcus.Templates.WebApi.csproj +++ b/src/Arcus.Templates.WebApi/Arcus.Templates.WebApi.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 true Arcus.Templates.WebApi.Open-Api.xml Linux @@ -53,7 +53,7 @@ - + @@ -65,16 +65,15 @@ - - - - - - - - - - + + + + + + + + + diff --git a/src/Arcus.Templates.WebApi/Program.cs b/src/Arcus.Templates.WebApi/Program.cs index 3b34403f..6b25e2ad 100644 --- a/src/Arcus.Templates.WebApi/Program.cs +++ b/src/Arcus.Templates.WebApi/Program.cs @@ -139,12 +139,7 @@ private static void ConfigureServices(WebApplicationBuilder builder, IConfigurat options.ReturnHttpNotAcceptable = true; options.RespectBrowserAcceptHeader = true; options.OnlyAllowJsonFormatting(); - options.ConfigureJsonFormatting(json => - { - json.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; - json.Converters.Add(new JsonStringEnumConverter()); - }); - + #if SharedAccessKeyAuth #warning Please provide a valid request header name and secret name to the shared access filter options.AddSharedAccessKeyAuthenticationFilterOnHeader(SharedAccessKeyHeaderName, ""); @@ -164,6 +159,10 @@ private static void ConfigureServices(WebApplicationBuilder builder, IConfigurat options.Filters.Add(new AuthorizeFilter(policy)); #endif + }).AddJsonOptions(json => + { + json.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + json.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); #if JwtAuth #error Use previously registered secret provider, for example Azure Key Vault: https://security.arcus-azure.net/features/secrets/consume-from-key-vault @@ -323,7 +322,7 @@ private static void ConfigureHost(WebApplicationBuilder builder, IConfiguration builder.Host.UseSerilog(Log.Logger); #endif #if Console - builder.Host.ConfigureLogging(logging => logging.AddConsole()); + builder.Logging.AddConsole(); #endif } From f41d1b00567f247d34db46b59375956d28312ae2 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 7 May 2024 08:01:04 +0200 Subject: [PATCH 02/15] pr-fix: use net8.0 in ci build --- build/variables/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/variables/build.yml b/build/variables/build.yml index ef82e44d..e91697d1 100644 --- a/build/variables/build.yml +++ b/build/variables/build.yml @@ -1,4 +1,4 @@ variables: - DotNet.Sdk.Version: '6.0.100' + DotNet.Sdk.Version: '8.0.x' Project: 'Arcus.Templates' Vm.Image: 'ubuntu-latest' From 5fe4af72428fd1e06adb86e219e5fac900e33fd6 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 7 May 2024 08:10:55 +0200 Subject: [PATCH 03/15] pr-fix: use diff dotnet import for docker tests --- build/templates/docker-integration-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/templates/docker-integration-tests.yml b/build/templates/docker-integration-tests.yml index 529b8f84..3326eb39 100644 --- a/build/templates/docker-integration-tests.yml +++ b/build/templates/docker-integration-tests.yml @@ -14,9 +14,10 @@ stages: inputs: artifact: 'Templates' path: '$(Build.SourcesDirectory)/templates' - - task: DotNetCoreInstaller@0 + - task: UseDotNet@0 displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))' inputs: + packageType: 'sdk' version: '$(DotNet.Sdk.Version)' - task: DotNetCoreCLI@2 displayName: 'Install template' From a2357d1787f4fcb1eb20233afad68a9a34f0ee6c Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 7 May 2024 09:07:58 +0200 Subject: [PATCH 04/15] pr-fix: remove arcus evengrid from integration tests --- .../AzureFunctionsServiceBusProject.cs | 3 +-- .../Worker/Health/HealthEndpointService.cs | 2 +- .../Worker/Health/TcpHealthProbeTests.cs | 1 + .../ServiceBus/Fixture/OrderCreatedEvent.cs | 17 ----------------- .../Worker/ServiceBusWorkerProject.cs | 4 ++-- 5 files changed, 5 insertions(+), 22 deletions(-) delete mode 100644 src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/OrderCreatedEvent.cs diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs index 8ef4f175..a77fe9cf 100644 --- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs @@ -134,11 +134,10 @@ public static AzureFunctionsServiceBusProject CreateNew( private void AddOrderMessageHandlerImplementation() { - AddPackage("Arcus.EventGrid.Core", "3.3.0"); + AddPackage("Azure.Messaging.EventGrid", "4.11.0"); AddTypeAsFile(); AddTypeAsFile(); - AddTypeAsFile(); AddTypeAsFile(); AddTypeAsFile(); diff --git a/src/Arcus.Templates.Tests.Integration/Worker/Health/HealthEndpointService.cs b/src/Arcus.Templates.Tests.Integration/Worker/Health/HealthEndpointService.cs index 150880ca..db5e711b 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/Health/HealthEndpointService.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/Health/HealthEndpointService.cs @@ -60,7 +60,7 @@ public async Task ProbeHealthAsync() JObject json = JObject.Parse(healthReportJson); Assert.NotNull(json); - JToken statusToken = json["Status"]; + JToken statusToken = json["status"]; Assert.NotNull(statusToken); var status = Enum.Parse(statusToken.ToString()); diff --git a/src/Arcus.Templates.Tests.Integration/Worker/Health/TcpHealthProbeTests.cs b/src/Arcus.Templates.Tests.Integration/Worker/Health/TcpHealthProbeTests.cs index 64418b29..b84c2116 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/Health/TcpHealthProbeTests.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/Health/TcpHealthProbeTests.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Arcus.Templates.Tests.Integration.Fixture; using Microsoft.Extensions.Diagnostics.HealthChecks; using Newtonsoft.Json; using Xunit; diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/OrderCreatedEvent.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/OrderCreatedEvent.cs deleted file mode 100644 index 5c301622..00000000 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/OrderCreatedEvent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Arcus.Messaging.Abstractions; -using Azure.Messaging.EventGrid; - -namespace Arcus.Templates.Tests.Integration.Worker.ServiceBus.Fixture -{ - public class OrderCreatedEvent : EventGridEvent - { - private const string DefaultDataVersion = "1"; - private const string DefaultEventType = "Arcus.Samples.Orders.OrderCreated"; - - public OrderCreatedEvent(string eventId, string orderId, int amount, string articleNumber, string customerName, MessageCorrelationInfo correlationInfo) - : base($"customer/{customerName}", DefaultEventType, DefaultDataVersion, new OrderCreatedEventData(orderId, amount, articleNumber, customerName, correlationInfo)) - { - Id = eventId; - } - } -} \ No newline at end of file diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs index 9e400ff2..15a02297 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs @@ -167,10 +167,10 @@ public static ServiceBusWorkerProject CreateNew( private void AddTestMessageHandler() { - AddPackage("Arcus.EventGrid.Core", "3.3.0"); + AddPackage("Azure.Messaging.EventGrid", "4.11.0"); + AddTypeAsFile(); AddTypeAsFile(); - AddTypeAsFile(); AddTypeAsFile(); AddTypeAsFile(); From a3c3fafa6cb0970b40483c1f656fb91a964ba9e5 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 8 May 2024 12:58:15 +0200 Subject: [PATCH 05/15] pr-fix: remove arcus eventgrid packages implicit references --- .../Arcus.Templates.Tests.Integration.csproj | 1 - .../AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs | 3 ++- .../Worker/EventHubsWorkerProject.cs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj b/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj index d9af13df..42f8e571 100644 --- a/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj +++ b/src/Arcus.Templates.Tests.Integration/Arcus.Templates.Tests.Integration.csproj @@ -29,7 +29,6 @@ - diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs index 2bb4e5df..2dca60cd 100644 --- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs @@ -108,7 +108,8 @@ public static AzureFunctionsEventHubsProject CreateNew( private void AddTestMessageHandler(EventHubsConfig eventHubsConfig) { - AddPackage("Arcus.EventGrid.Core", "3.3.0"); + AddPackage("Azure.Messaging.EventGrid", "4.11.0"); + AddTypeAsFile(); AddTypeAsFile(); AddTypeAsFile(); diff --git a/src/Arcus.Templates.Tests.Integration/Worker/EventHubsWorkerProject.cs b/src/Arcus.Templates.Tests.Integration/Worker/EventHubsWorkerProject.cs index 91852213..2650c21f 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/EventHubsWorkerProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/EventHubsWorkerProject.cs @@ -91,7 +91,8 @@ private static async Task CreateNewAsync( private void AddTestMessageHandler() { - AddPackage("Arcus.EventGrid.Core", "3.3.0"); + AddPackage("Azure.Messaging.EventGrid", "4.11.0"); + AddTypeAsFile(); AddTypeAsFile(); AddTypeAsFile(); From 468a3d52ecd8c9328840dea816af45e301ef2505 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 9 May 2024 13:55:10 +0200 Subject: [PATCH 06/15] pr-fix: remove dotnet install in docker integration tests --- build/templates/docker-integration-tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build/templates/docker-integration-tests.yml b/build/templates/docker-integration-tests.yml index 3326eb39..5403831c 100644 --- a/build/templates/docker-integration-tests.yml +++ b/build/templates/docker-integration-tests.yml @@ -14,11 +14,6 @@ stages: inputs: artifact: 'Templates' path: '$(Build.SourcesDirectory)/templates' - - task: UseDotNet@0 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.Version)' - task: DotNetCoreCLI@2 displayName: 'Install template' inputs: From dde5c760f641f8c2d8e2133cbd24c3c775820812 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 9 May 2024 13:55:58 +0200 Subject: [PATCH 07/15] pr-fix: use automatic topic subscription --- src/Arcus.Templates.ServiceBus.Queue/Program.cs | 4 ++-- src/Arcus.Templates.ServiceBus.Topic/Program.cs | 4 ++-- .../Worker/ServiceBusWorkerProject.cs | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Arcus.Templates.ServiceBus.Queue/Program.cs b/src/Arcus.Templates.ServiceBus.Queue/Program.cs index 57352834..53a10e54 100644 --- a/src/Arcus.Templates.ServiceBus.Queue/Program.cs +++ b/src/Arcus.Templates.ServiceBus.Queue/Program.cs @@ -44,7 +44,7 @@ public static async Task Main(string[] args) } finally { - Log.CloseAndFlush(); + await Log.CloseAndFlushAsync(); } #else CreateHostBuilder(args) @@ -82,7 +82,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) services.AddAssemblyAppVersion(); #endif - services.AddServiceBusQueueMessagePump(secretProvider => secretProvider.GetRawSecretAsync("ARCUS_SERVICEBUS_CONNECTIONSTRING")) + services.AddServiceBusQueueMessagePump("ARCUS_SERVICEBUS_CONNECTIONSTRING") .WithServiceBusMessageHandler(); services.AddTcpHealthProbes("ARCUS_HEALTH_PORT"); diff --git a/src/Arcus.Templates.ServiceBus.Topic/Program.cs b/src/Arcus.Templates.ServiceBus.Topic/Program.cs index a001ded3..9883a93a 100644 --- a/src/Arcus.Templates.ServiceBus.Topic/Program.cs +++ b/src/Arcus.Templates.ServiceBus.Topic/Program.cs @@ -44,7 +44,7 @@ public static async Task Main(string[] args) } finally { - Log.CloseAndFlush(); + await Log.CloseAndFlushAsync(); } #else IHost host = CreateHostBuilder(args).Build(); @@ -81,7 +81,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) services.AddAssemblyAppVersion(); #endif - services.AddServiceBusTopicMessagePump("Receive-All", secretProvider => secretProvider.GetRawSecretAsync("ARCUS_SERVICEBUS_CONNECTIONSTRING")) + services.AddServiceBusTopicMessagePump("Receive-All", "ARCUS_SERVICEBUS_CONNECTIONSTRING") .WithServiceBusMessageHandler(); services.AddTcpHealthProbes("ARCUS_HEALTH_PORT"); diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs index 15a02297..dd7c33e1 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Arcus.Messaging.Pumps.ServiceBus; using Arcus.Templates.Tests.Integration.Fixture; using Arcus.Templates.Tests.Integration.Worker.Configuration; using Arcus.Templates.Tests.Integration.Worker.ServiceBus.Fixture; @@ -130,7 +131,7 @@ public static async Task StartNewAsync( EventGridConfig eventGridConfig = configuration.GetEventGridConfig(); string serviceBusConnection = configuration.GetServiceBusConnectionString(entityType); - await project.StartAsync(options, + await project.StartAsync(options, CommandArgument.CreateSecret("EVENTGRID_TOPIC_URI", eventGridConfig.TopicUri), CommandArgument.CreateSecret("EVENTGRID_AUTH_KEY", eventGridConfig.AuthenticationKey), CommandArgument.CreateSecret("ARCUS_SERVICEBUS_CONNECTIONSTRING", serviceBusConnection)); @@ -162,9 +163,22 @@ public static ServiceBusWorkerProject CreateNew( project.CreateNewProject(options); project.AddTestMessageHandler(); + if (entityType is ServiceBusEntityType.Topic) + { + project.AddAutomaticTopicSubscription(); + } + return project; } + private void AddAutomaticTopicSubscription() + { + UpdateFileInProject("Program.cs", + contents => contents.Replace( + "AddServiceBusTopicMessagePump(\"Receive-All\", \"ARCUS_SERVICEBUS_CONNECTIONSTRING\")", + $"AddServiceBusTopicMessagePump(\"Receive-All\", \"ARCUS_SERVICEBUS_CONNECTIONSTRING\", opt => opt.TopicSubscription = {typeof(TopicSubscription).FullName}.{TopicSubscription.Automatic})")); + } + private void AddTestMessageHandler() { AddPackage("Azure.Messaging.EventGrid", "4.11.0"); From e264d5be3cf22dc1840a3ed91095a7d986a3f3be Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 9 May 2024 14:05:05 +0200 Subject: [PATCH 08/15] pr-fix: update Dockerfiles --- src/Arcus.Templates.AzureFunctions.EventHubs/Dockerfile | 2 +- src/Arcus.Templates.AzureFunctions.Http/Dockerfile | 2 +- .../Dockerfile | 2 +- .../Dockerfile | 2 +- src/Arcus.Templates.EventHubs/Dockerfile | 4 ++-- src/Arcus.Templates.ServiceBus.Queue/Dockerfile | 4 ++-- src/Arcus.Templates.ServiceBus.Topic/Dockerfile | 4 ++-- src/Arcus.Templates.WebApi/Dockerfile | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Arcus.Templates.AzureFunctions.EventHubs/Dockerfile b/src/Arcus.Templates.AzureFunctions.EventHubs/Dockerfile index 065ffb3a..9596658e 100644 --- a/src/Arcus.Templates.AzureFunctions.EventHubs/Dockerfile +++ b/src/Arcus.Templates.AzureFunctions.EventHubs/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/azure-functions/dotnet:4 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:7.0.203-bullseye-slim AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build WORKDIR /src COPY ["Arcus.Templates.AzureFunctions.EventHubs.csproj", ""] diff --git a/src/Arcus.Templates.AzureFunctions.Http/Dockerfile b/src/Arcus.Templates.AzureFunctions.Http/Dockerfile index 344c8171..5aba7cf4 100644 --- a/src/Arcus.Templates.AzureFunctions.Http/Dockerfile +++ b/src/Arcus.Templates.AzureFunctions.Http/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/azure-functions/dotnet:4 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:7.0.203-bullseye-slim AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build WORKDIR /src COPY ["Arcus.Templates.AzureFunctions.Http.csproj", ""] diff --git a/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Dockerfile b/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Dockerfile index 7dfabfda..615b83fe 100644 --- a/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Dockerfile +++ b/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/azure-functions/dotnet:4 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:7.0.203-bullseye-slim AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build WORKDIR /src COPY ["Arcus.Templates.AzureFunctions.ServiceBus.Queue.csproj", ""] diff --git a/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Dockerfile b/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Dockerfile index b53cea82..02b7a25b 100644 --- a/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Dockerfile +++ b/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/azure-functions/dotnet:4 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:7.0.203-bullseye-slim AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build WORKDIR /src COPY ["Arcus.Templates.AzureFunctions.ServiceBus.Topic.csproj", ""] diff --git a/src/Arcus.Templates.EventHubs/Dockerfile b/src/Arcus.Templates.EventHubs/Dockerfile index a0ec2eb5..d6ad4271 100644 --- a/src/Arcus.Templates.EventHubs/Dockerfile +++ b/src/Arcus.Templates.EventHubs/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0.301-alpine3.14 AS base +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:6.0.301-alpine3.14 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build WORKDIR /src COPY ["Arcus.Templates.EventHubs.csproj", ""] diff --git a/src/Arcus.Templates.ServiceBus.Queue/Dockerfile b/src/Arcus.Templates.ServiceBus.Queue/Dockerfile index 40ffcbb5..6b5de53b 100644 --- a/src/Arcus.Templates.ServiceBus.Queue/Dockerfile +++ b/src/Arcus.Templates.ServiceBus.Queue/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0.301-alpine3.14 AS base +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:6.0.301-alpine3.14 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build WORKDIR /src COPY ["Arcus.Templates.ServiceBus.Queue.csproj", ""] diff --git a/src/Arcus.Templates.ServiceBus.Topic/Dockerfile b/src/Arcus.Templates.ServiceBus.Topic/Dockerfile index e7b9e10f..52545d76 100644 --- a/src/Arcus.Templates.ServiceBus.Topic/Dockerfile +++ b/src/Arcus.Templates.ServiceBus.Topic/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0.301-alpine3.14 AS base +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:6.0.301-alpine3.14 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build WORKDIR /src COPY ["Arcus.Templates.ServiceBus.Topic.csproj", ""] diff --git a/src/Arcus.Templates.WebApi/Dockerfile b/src/Arcus.Templates.WebApi/Dockerfile index 1fd64611..fa25f03e 100644 --- a/src/Arcus.Templates.WebApi/Dockerfile +++ b/src/Arcus.Templates.WebApi/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0.6-alpine3.14 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:6.0.301-alpine3.14 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build WORKDIR /src COPY ["Arcus.Templates.WebApi.csproj", ""] From 722385dde2568d90f9ab8c490c62840e43c771f8 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 9 May 2024 17:49:23 +0200 Subject: [PATCH 09/15] pr-revert: program file improvements --- src/Arcus.Templates.ServiceBus.Queue/Program.cs | 4 ++-- src/Arcus.Templates.ServiceBus.Topic/Program.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Arcus.Templates.ServiceBus.Queue/Program.cs b/src/Arcus.Templates.ServiceBus.Queue/Program.cs index 53a10e54..57352834 100644 --- a/src/Arcus.Templates.ServiceBus.Queue/Program.cs +++ b/src/Arcus.Templates.ServiceBus.Queue/Program.cs @@ -44,7 +44,7 @@ public static async Task Main(string[] args) } finally { - await Log.CloseAndFlushAsync(); + Log.CloseAndFlush(); } #else CreateHostBuilder(args) @@ -82,7 +82,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) services.AddAssemblyAppVersion(); #endif - services.AddServiceBusQueueMessagePump("ARCUS_SERVICEBUS_CONNECTIONSTRING") + services.AddServiceBusQueueMessagePump(secretProvider => secretProvider.GetRawSecretAsync("ARCUS_SERVICEBUS_CONNECTIONSTRING")) .WithServiceBusMessageHandler(); services.AddTcpHealthProbes("ARCUS_HEALTH_PORT"); diff --git a/src/Arcus.Templates.ServiceBus.Topic/Program.cs b/src/Arcus.Templates.ServiceBus.Topic/Program.cs index 9883a93a..725e4a7b 100644 --- a/src/Arcus.Templates.ServiceBus.Topic/Program.cs +++ b/src/Arcus.Templates.ServiceBus.Topic/Program.cs @@ -43,8 +43,8 @@ public static async Task Main(string[] args) return 1; } finally - { - await Log.CloseAndFlushAsync(); + { + Log.CloseAndFlush(); } #else IHost host = CreateHostBuilder(args).Build(); @@ -81,7 +81,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) services.AddAssemblyAppVersion(); #endif - services.AddServiceBusTopicMessagePump("Receive-All", "ARCUS_SERVICEBUS_CONNECTIONSTRING") + services.AddServiceBusTopicMessagePump("Receive-All", secretProvider => secretProvider.GetRawSecretAsync("ARCUS_SERVICEBUS_CONNECTIONSTRING")) .WithServiceBusMessageHandler(); services.AddTcpHealthProbes("ARCUS_HEALTH_PORT"); From e01d30edbfb0bce097c7a8a8f75455ef95bf506b Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 9 May 2024 17:54:54 +0200 Subject: [PATCH 10/15] pr-revert: unnecessary blank space in program --- src/Arcus.Templates.ServiceBus.Topic/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arcus.Templates.ServiceBus.Topic/Program.cs b/src/Arcus.Templates.ServiceBus.Topic/Program.cs index 725e4a7b..a001ded3 100644 --- a/src/Arcus.Templates.ServiceBus.Topic/Program.cs +++ b/src/Arcus.Templates.ServiceBus.Topic/Program.cs @@ -43,7 +43,7 @@ public static async Task Main(string[] args) return 1; } finally - { + { Log.CloseAndFlush(); } #else From 0a0cd86d147fbf04cff3a773631a6c1739667fdc Mon Sep 17 00:00:00 2001 From: Stijn Moreels <9039753+stijnmoreels@users.noreply.github.com> Date: Fri, 10 May 2024 06:58:49 +0200 Subject: [PATCH 11/15] pr-fix: remove pinned az cli tool --- build/ci-build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index 62cc182e..b4219434 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -89,8 +89,6 @@ stages: steps: - task: FuncToolsInstaller@0 displayName: 'Install Azure Functions Core tools' - inputs: - version: '4.0.5390' - template: test/run-integration-tests.yml@templates parameters: dotnetSdkVersion: '$(DotNet.Sdk.Version)' From 7f2d85c0f7c6254ebf3f1db235976aeaf4ed3c5f Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 15 May 2024 08:22:16 +0200 Subject: [PATCH 12/15] pr-temp: verify if the problem is timeout --- .../Worker/Fixture/TestServiceBusMessageEventConsumer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs b/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs index 27458e81..8e895c56 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs @@ -52,7 +52,7 @@ public static async Task StartNewAsync(TestC /// Thrown when the is blank. public TEventData ConsumeEvent(string eventId) { - string receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(eventId, retryCount: 10); + string receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(eventId, retryCount: 15); Assert.NotEmpty(receivedEvent); BinaryData data = BinaryData.FromString(receivedEvent); From 7a1f37377a22a154a165f91792721d35703f354a Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 15 May 2024 10:22:43 +0200 Subject: [PATCH 13/15] pr-fix: remove eventgrid from servicebus test message hanlder --- .../AzureFunctionsServiceBusProject.cs | 8 +- .../TestServiceBusMessageEventConsumer.cs | 2 +- ...TestOrdersAzureServiceBusMessageHandler.cs | 80 ------------------- .../TestServiceBusMessagePumpService.cs | 59 +++++++++----- .../Fixture/WriteToFileMessageHandler.cs | 33 ++++++++ .../Worker/ServiceBusWorkerProject.cs | 11 +-- .../Worker/WorkerProject.cs | 13 ++- 7 files changed, 89 insertions(+), 117 deletions(-) delete mode 100644 src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestOrdersAzureServiceBusMessageHandler.cs create mode 100644 src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs index a77fe9cf..60ad5f17 100644 --- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs @@ -32,7 +32,7 @@ private AzureFunctionsServiceBusProject( options, outputWriter) { - Messaging = new TestServiceBusMessagePumpService(entityType, configuration, outputWriter); + Messaging = new TestServiceBusMessagePumpService(entityType, configuration, ProjectDirectory, outputWriter); Admin = new AdminEndpointService(RootEndpoint.Port, "order-processing", outputWriter); } @@ -134,16 +134,14 @@ public static AzureFunctionsServiceBusProject CreateNew( private void AddOrderMessageHandlerImplementation() { - AddPackage("Azure.Messaging.EventGrid", "4.11.0"); - AddTypeAsFile(); AddTypeAsFile(); AddTypeAsFile(); - AddTypeAsFile(); + AddTypeAsFile(); UpdateFileInProject(RuntimeFileName, contents => RemovesUserErrorsFromContents(contents) - .Replace("OrdersAzureServiceBusMessageHandler", nameof(TestOrdersAzureServiceBusMessageHandler))); + .Replace("OrdersAzureServiceBusMessageHandler", nameof(WriteToFileMessageHandler))); } private async Task StartAsync(ServiceBusEntityType entityType) diff --git a/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs b/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs index 8e895c56..27458e81 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/Fixture/TestServiceBusMessageEventConsumer.cs @@ -52,7 +52,7 @@ public static async Task StartNewAsync(TestC /// Thrown when the is blank. public TEventData ConsumeEvent(string eventId) { - string receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(eventId, retryCount: 15); + string receivedEvent = _serviceBusEventConsumerHost.GetReceivedEvent(eventId, retryCount: 10); Assert.NotEmpty(receivedEvent); BinaryData data = BinaryData.FromString(receivedEvent); diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestOrdersAzureServiceBusMessageHandler.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestOrdersAzureServiceBusMessageHandler.cs deleted file mode 100644 index d013234b..00000000 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestOrdersAzureServiceBusMessageHandler.cs +++ /dev/null @@ -1,80 +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 Azure; -using Azure.Messaging; -using Azure.Messaging.EventGrid; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; - -namespace Arcus.Templates.Tests.Integration.Worker.ServiceBus.Fixture -{ - public class TestOrdersAzureServiceBusMessageHandler : IAzureServiceBusMessageHandler - { - private readonly ILogger _logger; - private readonly EventGridPublisherClient _eventGridPublisher; - - /// - /// Constructor - /// - /// Configuration of the application - /// Logger to write telemetry to - public TestOrdersAzureServiceBusMessageHandler(IConfiguration configuration, ILogger logger) - { - _logger = logger; - var eventGridTopic = configuration.GetValue("EVENTGRID_TOPIC_URI"); - var eventGridKey = configuration.GetValue("EVENTGRID_AUTH_KEY"); - - _eventGridPublisher = new EventGridPublisherClient(new Uri(eventGridTopic), new AzureKeyCredential(eventGridKey)); - } - - /// Process a new message that was received - /// Message that was received - /// Context providing more information concerning the processing - /// - /// Information concerning correlation of telemetry and processes by using a variety of unique - /// identifiers - /// - /// Cancellation token - public async Task ProcessMessageAsync( - Order message, - AzureServiceBusMessageContext messageContext, - MessageCorrelationInfo correlationInfo, - CancellationToken cancellationToken) - { - _logger.LogInformation( - "Processing order {OrderId} for {OrderAmount} units of {OrderArticle}", - message.Id, message.Amount, message.ArticleNumber); - - await PublishEventToEventGridAsync(message, correlationInfo); - - _logger.LogInformation("Order {OrderId} processed", message.Id); - } - - private async Task PublishEventToEventGridAsync(Order orderMessage, MessageCorrelationInfo correlationInfo) - { - var eventData = new OrderCreatedEventData( - orderMessage.Id, - orderMessage.Amount, - orderMessage.ArticleNumber, - $"{orderMessage.Customer.FirstName} {orderMessage.Customer.LastName}", - correlationInfo); - - var orderCreatedEvent = new CloudEvent( - "http://test-host", - "OrderCreatedEvent", - jsonSerializableData: eventData) - { - Id = correlationInfo.TransactionId, - Time = DateTimeOffset.UtcNow - }; - - await _eventGridPublisher.SendEventAsync(orderCreatedEvent); - - _logger.LogInformation("Event {EventId} was published with subject {EventSubject}", orderCreatedEvent.Id, orderCreatedEvent.Subject); - } - } -} diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestServiceBusMessagePumpService.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestServiceBusMessagePumpService.cs index 847f4407..36eae5da 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestServiceBusMessagePumpService.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/TestServiceBusMessagePumpService.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Threading.Tasks; using Arcus.Templates.Tests.Integration.Fixture; using Arcus.Templates.Tests.Integration.Logging; @@ -6,6 +7,8 @@ using Azure.Messaging.ServiceBus; using Bogus; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Polly; using Xunit; using Xunit.Abstractions; @@ -15,48 +18,36 @@ public class TestServiceBusMessagePumpService : IMessagingService { private readonly ServiceBusEntityType _entityType; private readonly TestConfig _configuration; + private readonly DirectoryInfo _projectDirectory; private readonly ILogger _logger; - private TestServiceBusMessageEventConsumer _serviceBusMessageEventConsumer; - /// /// Initializes a new instance of the class. /// public TestServiceBusMessagePumpService( ServiceBusEntityType entityType, TestConfig configuration, + DirectoryInfo projectDirectory, ITestOutputHelper outputWriter) { _entityType = entityType; _configuration = configuration; + _projectDirectory = projectDirectory; _logger = new XunitTestLogger(outputWriter); } - public async Task StartAsync() + public Task StartAsync() { - if (_serviceBusMessageEventConsumer is null) - { - _serviceBusMessageEventConsumer = await TestServiceBusMessageEventConsumer.StartNewAsync(_configuration, _logger); - } - else - { - throw new InvalidOperationException("Service is already started!"); - } + return Task.CompletedTask; } public async Task SimulateMessageProcessingAsync() { - if (_serviceBusMessageEventConsumer is null) - { - throw new InvalidOperationException( - "Cannot simulate the message pump because the service is not yet started; please start this service before simulating"); - } - var traceParent = TraceParent.Generate(); Order order = GenerateOrder(); await ProduceMessageAsync(order, traceParent); - var orderCreatedEventData = _serviceBusMessageEventConsumer.ConsumeEvent(traceParent.TransactionId); + OrderCreatedEventData orderCreatedEventData = await ConsumeMessageAsync(traceParent); Assert.NotNull(orderCreatedEventData); Assert.NotNull(orderCreatedEventData.CorrelationInfo); Assert.Equal(order.Id, orderCreatedEventData.Id); @@ -84,6 +75,8 @@ private static Order GenerateOrder() private async Task ProduceMessageAsync(Order order, TraceParent traceParent) { + _logger.LogTrace("Produces a message with transaction ID: {TransactionId}", traceParent.TransactionId); + var message = new ServiceBusMessage(BinaryData.FromObjectAsJson(order)); message.ApplicationProperties["Diagnostic-Id"] = traceParent.DiagnosticId; @@ -104,12 +97,36 @@ private async Task ProduceMessageAsync(Order order, TraceParent traceParent) } } - public async ValueTask DisposeAsync() + private async Task ConsumeMessageAsync(TraceParent traceParent) { - if (_serviceBusMessageEventConsumer != null) + try { - await _serviceBusMessageEventConsumer.DisposeAsync(); + _logger.LogTrace("Consumes a message with transaction ID: {TransactionId}", traceParent.TransactionId); + + FileInfo[] foundFiles = + Policy.Timeout(TimeSpan.FromMinutes(1)) + .Wrap(Policy.HandleResult((FileInfo[] files) => files.Length <= 0) + .WaitAndRetryForever(_ => TimeSpan.FromMilliseconds(200))) + .Execute(() => _projectDirectory.GetFiles(traceParent.TransactionId + ".json", SearchOption.AllDirectories)); + + FileInfo found = Assert.Single(foundFiles); + string json = await File.ReadAllTextAsync(found.FullName); + var settings = new JsonSerializerSettings(); + settings.Converters.Add(new MessageCorrelationInfoJsonConverter()); + + return JsonConvert.DeserializeObject(json, settings); + } + catch (TimeoutException ex) + { + throw new TimeoutException( + "Failed to retrieve the necessary produced message from the temporary project created from the worker project template, " + + "please check whether the injected message handler was correct and if the created project correctly receives the message", ex); } } + + public ValueTask DisposeAsync() + { + return ValueTask.CompletedTask; + } } } diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs new file mode 100644 index 00000000..2292974d --- /dev/null +++ b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs @@ -0,0 +1,33 @@ +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Arcus.Messaging.Abstractions; +using Arcus.Messaging.Abstractions.ServiceBus; +using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; + +namespace Arcus.Templates.Tests.Integration.Worker.ServiceBus.Fixture +{ + public class WriteToFileMessageHandler : IAzureServiceBusMessageHandler + { + public Task ProcessMessageAsync( + Order orderMessage, + AzureServiceBusMessageContext messageContext, + MessageCorrelationInfo correlationInfo, + CancellationToken cancellationToken) + { + var eventData = new OrderCreatedEventData( + orderMessage.Id, + orderMessage.Amount, + orderMessage.ArticleNumber, + $"{orderMessage.Customer.FirstName} {orderMessage.Customer.LastName}", + correlationInfo); + + string json = JsonSerializer.Serialize(eventData); + string currentDirPath = Directory.GetCurrentDirectory(); + File.WriteAllText(Path.Combine(currentDirPath, $"{correlationInfo.TransactionId}.json"), json); + + return Task.CompletedTask; + } + } +} diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs index dd7c33e1..36585986 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs @@ -4,7 +4,6 @@ using Arcus.Templates.Tests.Integration.Worker.Configuration; using Arcus.Templates.Tests.Integration.Worker.ServiceBus.Fixture; using GuardNet; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Xunit.Abstractions; @@ -21,9 +20,9 @@ private ServiceBusWorkerProject( ITestOutputHelper outputWriter) : base(configuration.GetServiceBusProjectDirectory(entityType), configuration, - new TestServiceBusMessagePumpService(entityType, configuration, outputWriter), - outputWriter) + outputWriter: outputWriter) { + Messaging = new TestServiceBusMessagePumpService(entityType, configuration, ProjectDirectory, outputWriter); } /// @@ -181,17 +180,15 @@ private void AddAutomaticTopicSubscription() private void AddTestMessageHandler() { - AddPackage("Azure.Messaging.EventGrid", "4.11.0"); - AddTypeAsFile(); AddTypeAsFile(); AddTypeAsFile(); - AddTypeAsFile(); + AddTypeAsFile(); UpdateFileInProject("Program.cs", contents => RemovesUserErrorsFromContents(contents) .Replace(".MinimumLevel.Debug()", ".MinimumLevel.Verbose()") - .Replace("EmptyMessageHandler", nameof(TestOrdersAzureServiceBusMessageHandler)) + .Replace("EmptyMessageHandler", nameof(WriteToFileMessageHandler)) .Replace("EmptyMessage", nameof(Order)) .Replace("stores.AddAzureKeyVaultWithManagedIdentity(\"https://your-keyvault.vault.azure.net/\", CacheConfiguration.Default);", "")); } diff --git a/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs b/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs index 53c92ca6..625e682b 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/WorkerProject.cs @@ -22,17 +22,24 @@ public class WorkerProject : TemplateProject, IAsyncDisposable protected WorkerProject( DirectoryInfo templateDirectory, TestConfig configuration, - IMessagingService messagingService, ITestOutputHelper outputWriter) : base(templateDirectory, configuration.GetFixtureProjectDirectory(), outputWriter) { _healthPort = configuration.GenerateWorkerHealthPort(); _configuration = configuration; - Messaging = messagingService; Health = new HealthEndpointService(_healthPort, outputWriter); } + protected WorkerProject( + DirectoryInfo templateDirectory, + TestConfig configuration, + IMessagingService messaging, + ITestOutputHelper outputWriter) + : this(templateDirectory, configuration, outputWriter) + { + Messaging = messaging; + } /// /// Gets the service that interacts with the exposed health report information of the worker project. /// @@ -44,7 +51,7 @@ protected WorkerProject( /// /// Only when the project is started, is this service available for interaction. /// - public IMessagingService Messaging { get; set; } + public IMessagingService Messaging { get; protected init; } /// /// Starts a new .NET Worker project from a project template. From 2fee3aa4cfc45bc3802d43fe65c0b1921cc14c10 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 15 May 2024 10:44:57 +0200 Subject: [PATCH 14/15] pr-fix: simplify worker projects w/o eventgrid references --- .../ServiceBus/AzureFunctionsServiceBusProject.cs | 6 ------ .../Worker/ServiceBusWorkerProject.cs | 6 +----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs index 60ad5f17..bbae0f5f 100644 --- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs @@ -158,10 +158,6 @@ private async Task StartAsync(ServiceBusEntityType entityType) await AddServiceBusTopicSubscriptionAsync(properties.EntityPath, namespaceConnectionString); } - EventGridConfig eventGridConfig = Configuration.GetEventGridConfig(); - Environment.SetEnvironmentVariable("EVENTGRID_TOPIC_URI", eventGridConfig.TopicUri); - Environment.SetEnvironmentVariable("EVENTGRID_AUTH_KEY", eventGridConfig.AuthenticationKey); - string instrumentationKey = Configuration.GetApplicationInsightsInstrumentationKey(); Environment.SetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", instrumentationKey); Environment.SetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING", $"InstrumentationKey={instrumentationKey}"); @@ -234,8 +230,6 @@ protected override void Disposing(bool disposing) { base.Disposing(disposing); Environment.SetEnvironmentVariable("ServiceBusConnectionString", null); - Environment.SetEnvironmentVariable("EVENTGRID_TOPIC_URI", null); - Environment.SetEnvironmentVariable("EVENTGRID_AUTH_KEY", null); Environment.SetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", null); Environment.SetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING", null); } diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs index 36585986..82ec4dcb 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBusWorkerProject.cs @@ -127,13 +127,9 @@ public static async Task StartNewAsync( ServiceBusWorkerProject project = CreateNew(entityType, configuration, options, outputWriter); - EventGridConfig eventGridConfig = configuration.GetEventGridConfig(); string serviceBusConnection = configuration.GetServiceBusConnectionString(entityType); - await project.StartAsync(options, - CommandArgument.CreateSecret("EVENTGRID_TOPIC_URI", eventGridConfig.TopicUri), - CommandArgument.CreateSecret("EVENTGRID_AUTH_KEY", eventGridConfig.AuthenticationKey), - CommandArgument.CreateSecret("ARCUS_SERVICEBUS_CONNECTIONSTRING", serviceBusConnection)); + await project.StartAsync(options, CommandArgument.CreateSecret("ARCUS_SERVICEBUS_CONNECTIONSTRING", serviceBusConnection)); return project; } From c67b2425c152bbd0eadc56852da60bc502818e26 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 15 May 2024 10:59:42 +0200 Subject: [PATCH 15/15] pr-add: write log message upon message processing --- .../Fixture/WriteToFileMessageHandler.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs index 2292974d..d2dd2f3b 100644 --- a/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs +++ b/src/Arcus.Templates.Tests.Integration/Worker/ServiceBus/Fixture/WriteToFileMessageHandler.cs @@ -5,11 +5,22 @@ using Arcus.Messaging.Abstractions; using Arcus.Messaging.Abstractions.ServiceBus; using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; +using Microsoft.Extensions.Logging; namespace Arcus.Templates.Tests.Integration.Worker.ServiceBus.Fixture { public class WriteToFileMessageHandler : IAzureServiceBusMessageHandler { + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + public WriteToFileMessageHandler(ILogger logger) + { + _logger = logger; + } + public Task ProcessMessageAsync( Order orderMessage, AzureServiceBusMessageContext messageContext, @@ -25,7 +36,10 @@ public Task ProcessMessageAsync( string json = JsonSerializer.Serialize(eventData); string currentDirPath = Directory.GetCurrentDirectory(); - File.WriteAllText(Path.Combine(currentDirPath, $"{correlationInfo.TransactionId}.json"), json); + + var fileName = $"{correlationInfo.TransactionId}.json"; + _logger.LogTrace("Processed message by writing on disk: {FileName}", fileName); + File.WriteAllText(Path.Combine(currentDirPath, fileName), json); return Task.CompletedTask; }