Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageVersion Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.5" />
<PackageVersion Include="Mindscape.Raygun4Net.NetCore" Version="11.2.5" />
<PackageVersion Include="NLog.Extensions.Logging" Version="6.1.2" />
<PackageVersion Include="NServiceBus" Version="10.1.2" />
<PackageVersion Include="NServiceBus" Version="10.1.3" />
<PackageVersion Include="NServiceBus.AcceptanceTesting" Version="10.1.2" />
<PackageVersion Include="NServiceBus.AmazonSQS" Version="9.0.0" />
<PackageVersion Include="NServiceBus.CustomChecks" Version="6.0.0" />
Expand Down
59 changes: 47 additions & 12 deletions src/ServiceControl.Transports.ASBS/ASBSTransportCustomization.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace ServiceControl.Transports.ASBS
{
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Azure.Messaging.ServiceBus.Administration;
using BrokerThroughput;
using Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -71,18 +75,7 @@ protected override void AddTransportForPrimaryCore(IServiceCollection services,
{
TopicToPublishTo = connectionSettings.TopicName,
TopicToSubscribeOn = connectionSettings.TopicName,
EventsToMigrateMap =
[
"ServiceControl.Contracts.CustomCheckFailed",
"ServiceControl.Contracts.CustomCheckSucceeded",
"ServiceControl.Contracts.HeartbeatRestored",
"ServiceControl.Contracts.HeartbeatStopped",
"ServiceControl.Contracts.FailedMessagesArchived",
"ServiceControl.Contracts.FailedMessagesUnArchived",
"ServiceControl.Contracts.MessageFailed",
"ServiceControl.Contracts.MessageFailureResolvedByRetry",
"ServiceControl.Contracts.MessageFailureResolvedManually"
]
EventsToMigrateMap = [.. transportSettings.EventTypesPublished.Select(t => t.FullName)]
});
}
else if (SettingsReader.TryRead<string>(serviceBusRootNamespace, "Topology", out var topologyJson))
Expand All @@ -104,5 +97,47 @@ protected override void AddTransportForMonitoringCore(IServiceCollection service
services.AddSingleton<IProvideQueueLength, QueueLengthProvider>();
services.AddHostedService(provider => provider.GetRequiredService<IProvideQueueLength>());
}

public override async Task ProvisionQueues(TransportSettings transportSettings, IEnumerable<string> additionalQueues)
{
await base.ProvisionQueues(transportSettings, additionalQueues);

if (transportSettings.EventTypesPublished.Count == 0)
{
return;
}

var connectionSettings = ConnectionStringParser.Parse(transportSettings.ConnectionString);

var managementClient = connectionSettings.AuthenticationMethod.BuildManagementClient();

var creationTasks = new List<Task>(transportSettings.EventTypesPublished.Count);
foreach (var publishedTopic in transportSettings.EventTypesPublished)
{
creationTasks.Add(CreateTopic(publishedTopic.FullName));
}
await Task.WhenAll(creationTasks);

async Task CreateTopic(string publishedTopic)
{
var topicToPublishTo = new CreateTopicOptions(connectionSettings.HierarchyNamespace != null
? $"{connectionSettings.HierarchyNamespace}/{publishedTopic}"
: publishedTopic)
{
EnableBatchedOperations = true,
MaxSizeInMegabytes = 5 * 1024, // we are currently not configuring this in the connection string so it uses the same default as the transport
EnablePartitioning = connectionSettings.EnablePartitioning,
};

try
{
await managementClient.CreateTopicAsync(topicToPublishTo).ConfigureAwait(false);
}
catch (ServiceBusException sbe) when (sbe.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists || sbe.IsTransient)
{
// carry on
}
}
}
}
}
3 changes: 3 additions & 0 deletions src/ServiceControl.Transports/TransportSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ServiceControl.Transports
{
using System;
using System.Collections.Generic;
using System.Runtime.Loader;
using NServiceBus.Settings;

Expand All @@ -18,6 +19,8 @@ public class TransportSettings : SettingsHolder

public bool RunCustomChecks { get; set; }

public IReadOnlySet<Type> EventTypesPublished { get; init; } = new HashSet<Type>();

public string ErrorQueue
{
set;
Expand Down
12 changes: 9 additions & 3 deletions src/ServiceControl/ComponentInstallationContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
namespace Particular.ServiceControl
{
using System;
using System.Collections.Generic;

class ComponentInstallationContext : IComponentInstallationContext
public class ComponentInstallationContext : IComponentInstallationContext
{
public List<string> Queues { get; } = [];
public IReadOnlyCollection<string> Queues => queuesToCreate;
public IReadOnlySet<Type> EventTypesPublished => eventTypePublished;

public void CreateQueue(string queueName) => Queues.Add(queueName);
public void CreateQueue(string queueName) => queuesToCreate.Add(queueName);
public void AddEventPublished<TEvent>() => eventTypePublished.Add(typeof(TEvent));

readonly List<string> queuesToCreate = [];
readonly HashSet<Type> eventTypePublished = [];
}
}
14 changes: 13 additions & 1 deletion src/ServiceControl/CustomChecks/CustomChecksComponent.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
namespace ServiceControl.CustomChecks
{
using Connection;
using Contracts;
using ExternalIntegrations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using Particular.ServiceControl;
using ServiceBus.Management.Infrastructure.Settings;
using Transports;

class CustomChecksComponent : ServiceControlComponent
{
public override void Configure(Settings settings, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
public override void Setup(Settings settings, IComponentInstallationContext context, IHostApplicationBuilder hostBuilder)
{
// Integration Events
if (!settings.DisableExternalIntegrationsPublishing)
{
context.AddEventPublished<CustomCheckFailed>();
context.AddEventPublished<CustomCheckSucceeded>();
}
}

public override void Configure(Settings settings, EndpointConfiguration endpointConfiguration, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
{
hostBuilder.Services.AddIntegrationEventPublisher<CustomCheckFailedPublisher>();
hostBuilder.Services.AddIntegrationEventPublisher<CustomCheckSucceededPublisher>();
Expand Down
3 changes: 2 additions & 1 deletion src/ServiceControl/EventLog/EventLogComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
{
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using Particular.ServiceControl;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.Infrastructure.DomainEvents;
using Transports;

class EventLogComponent : ServiceControlComponent
{
public override void Configure(Settings settings, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
public override void Configure(Settings settings, EndpointConfiguration endpointConfiguration, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
{
var services = hostBuilder.Services;
services.AddSingleton<EventLogMappings>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
namespace ServiceControl.ExternalIntegrations
{
using Infrastructure.DomainEvents;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using Particular.ServiceControl;
using ServiceBus.Management.Infrastructure.Settings;
using Transports;

class ExternalIntegrationsComponent : ServiceControlComponent
{
public override void Configure(Settings settings, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
public override void Configure(Settings settings, EndpointConfiguration endpointConfiguration, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
{
var services = hostBuilder.Services;
services.AddEventLogMapping<ExternalIntegrationEventFailedToBePublishedDefinition>();

if (!settings.DisableExternalIntegrationsPublishing)
{
services.AddHostedService<EventDispatcherHostedService>();
services.AddDomainEventHandler<IntegrationEventWriter>();
endpointConfiguration.EnableFeature<ExternalIntegrationsFeature>();
}
}
}
}

This file was deleted.

17 changes: 9 additions & 8 deletions src/ServiceControl/HostApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Particular.ServiceControl
using System.Diagnostics;
using System.Runtime.InteropServices;
using global::ServiceControl.CustomChecks;
using global::ServiceControl.ExternalIntegrations;
using global::ServiceControl.Hosting;
using global::ServiceControl.Infrastructure;
using global::ServiceControl.Infrastructure.BackgroundTasks;
Expand Down Expand Up @@ -45,8 +44,15 @@ public static void AddServiceControl(this IHostApplicationBuilder hostBuilder, S
hostBuilder.Logging.ClearProviders();
hostBuilder.Logging.ConfigureLogging(settings.LoggingSettings.LogLevel);

var componentSetupContext = new ComponentInstallationContext();
var serviceControlComponents = ServiceControlMainInstance.Components;
foreach (ServiceControlComponent component in serviceControlComponents)
{
component.Setup(settings, componentSetupContext, hostBuilder);
}

var services = hostBuilder.Services;
var transportSettings = settings.ToTransportSettings();
var transportSettings = settings.ToTransportSettings(componentSetupContext);
var transportCustomization = TransportFactory.Create(transportSettings);
transportCustomization.AddTransportForPrimary(services, transportSettings);

Expand Down Expand Up @@ -81,11 +87,6 @@ public static void AddServiceControl(this IHostApplicationBuilder hostBuilder, S
NServiceBusFactory.Configure(settings, transportCustomization, transportSettings, configuration);
hostBuilder.UseNServiceBus(configuration);

if (!settings.DisableExternalIntegrationsPublishing)
{
hostBuilder.AddExternalIntegrationEvents();
}

hostBuilder.AddServicePulseSignalRNotifier();
hostBuilder.AddEmailNotifications();
hostBuilder.AddAsyncTimer();
Expand All @@ -101,7 +102,7 @@ public static void AddServiceControl(this IHostApplicationBuilder hostBuilder, S
hostBuilder.AddWindowsServiceWithRequestTimeout();
}

hostBuilder.AddServiceControlComponents(settings, transportCustomization, ServiceControlMainInstance.Components);
hostBuilder.AddServiceControlComponents(componentSetupContext, settings, configuration, transportCustomization, serviceControlComponents);
}

public static void AddServiceControlInstallers(this IHostApplicationBuilder hostApplicationBuilder, Settings settings)
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceControl/Hosting/Commands/SetupCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override async Task Execute(HostArguments args, Settings settings)
}
else
{
var transportSettings = settings.ToTransportSettings();
var transportSettings = settings.ToTransportSettings(componentSetupContext);
transportSettings.RunCustomChecks = false;
var transportCustomization = TransportFactory.Create(transportSettings);

Expand Down
3 changes: 2 additions & 1 deletion src/ServiceControl/HostingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ namespace Particular.ServiceControl
using global::ServiceControl.Transports;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using ServiceBus.Management.Infrastructure.Settings;

class HostingComponent : ServiceControlComponent
{
public override void Configure(Settings settings, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
public override void Configure(Settings settings, EndpointConfiguration endpointConfiguration, ITransportCustomization transportCustomization, IHostApplicationBuilder hostBuilder)
{
var services = hostBuilder.Services;
services.AddPlatformConnectionProvider<RemotePlatformConnectionDetailsProvider>();
Expand Down
4 changes: 3 additions & 1 deletion src/ServiceControl/IComponentInstallationContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace Particular.ServiceControl
{
interface IComponentInstallationContext
public interface IComponentInstallationContext
{
void CreateQueue(string queueName);

void AddEventPublished<TEvent>();
}
}
6 changes: 0 additions & 6 deletions src/ServiceControl/Infrastructure/NServiceBusFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace ServiceBus.Management.Infrastructure
using NServiceBus;
using NServiceBus.Configuration.AdvancedExtensibility;
using ServiceControl.Configuration;
using ServiceControl.ExternalIntegrations;
using ServiceControl.Infrastructure;
using ServiceControl.Infrastructure.Plugins;
using ServiceControl.Infrastructure.Subscriptions;
Expand Down Expand Up @@ -38,11 +37,6 @@ public static void Configure(Settings.Settings settings, ITransportCustomization
configuration.GetSettings().Set(settings.LoggingSettings);
configuration.SetDiagnosticsPath(settings.LoggingSettings.LogPath);

if (!settings.DisableExternalIntegrationsPublishing)
{
configuration.EnableFeature<ExternalIntegrationsFeature>();
}

var recoverability = configuration.Recoverability();
recoverability.Immediate(c => c.NumberOfRetries(3));
recoverability.Delayed(c => c.NumberOfRetries(0));
Expand Down
6 changes: 4 additions & 2 deletions src/ServiceControl/Infrastructure/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ServiceBus.Management.Infrastructure.Settings
using Microsoft.Extensions.Logging;
using NLog.Common;
using NServiceBus.Transport;
using Particular.ServiceControl;
using ServiceControl.Configuration;
using ServiceControl.Infrastructure;
using ServiceControl.Infrastructure.Settings;
Expand Down Expand Up @@ -238,7 +239,7 @@ public string GetConnectionString()
return connectionStringSettings?.ConnectionString;
}

public TransportSettings ToTransportSettings()
public TransportSettings ToTransportSettings(ComponentInstallationContext installationContext)
{
var transportSettings = new TransportSettings
{
Expand All @@ -247,7 +248,8 @@ public TransportSettings ToTransportSettings()
MaxConcurrency = MaximumConcurrencyLevel,
RunCustomChecks = true,
TransportType = TransportType,
AssemblyLoadContextResolver = AssemblyLoadContextResolver
AssemblyLoadContextResolver = AssemblyLoadContextResolver,
EventTypesPublished = installationContext.EventTypesPublished,
};
return transportSettings;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ServiceControl/Licensing/LicensingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ namespace Particular.ServiceControl;
using global::ServiceControl.LicenseManagement;
using global::ServiceControl.Transports;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using Particular.LicensingComponent;
using Particular.LicensingComponent.Shared;
using ServiceBus.Management.Infrastructure.Settings;

class LicensingComponent : ServiceControlComponent
{
public override void Configure(Settings settings, ITransportCustomization transportCustomization,
public override void Configure(Settings settings, EndpointConfiguration endpointConfiguration, ITransportCustomization transportCustomization,
IHostApplicationBuilder hostBuilder)
{
var licenseDetails = LicenseManager.FindLicense().Details;
Expand Down
Loading
Loading