Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageVersion Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.5" />
<PackageVersion Include="Mindscape.Raygun4Net.NetCore" Version="11.2.1" />
<PackageVersion Include="NLog.Extensions.Logging" Version="5.4.0" />
<PackageVersion Include="NServiceBus" Version="9.2.4" />
<PackageVersion Include="NServiceBus" Version="9.2.5" />
<PackageVersion Include="NServiceBus.AcceptanceTesting" Version="9.2.4" />
<PackageVersion Include="NServiceBus.AmazonSQS" Version="7.1.1" />
<PackageVersion Include="NServiceBus.CustomChecks" Version="5.0.1" />
Expand All @@ -41,7 +41,7 @@
<PackageVersion Include="NServiceBus.RabbitMQ" Version="9.2.0" />
<PackageVersion Include="NServiceBus.SagaAudit" Version="5.0.2" />
<PackageVersion Include="NServiceBus.Testing" Version="9.0.1" />
<PackageVersion Include="NServiceBus.Transport.AzureServiceBus" Version="4.2.4" />
<PackageVersion Include="NServiceBus.Transport.AzureServiceBus" Version="5.0.0" />
<PackageVersion Include="NServiceBus.Transport.AzureStorageQueues" Version="13.0.2" />
<PackageVersion Include="NServiceBus.Transport.Msmq.Sources" Version="3.0.2" />
<PackageVersion Include="NServiceBus.Transport.SqlServer" Version="8.1.7" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceControl.Configuration\ServiceControl.Configuration.csproj" />
<ProjectReference Include="..\ServiceControl.Transports.ASBS\ServiceControl.Transports.ASBS.csproj" />
<!-- Needed to bring the dependencies that the transport plugin excludes -->
<ProjectReference Include="..\ServiceControl.Transports\ServiceControl.Transports.csproj" />
Expand Down
64 changes: 58 additions & 6 deletions src/ServiceControl.Transports.ASBS/ASBSTransportCustomization.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace ServiceControl.Transports.ASBS
{
using System.Linq;
using System.Text.Json;
using BrokerThroughput;
using Configuration;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus;
using NServiceBus.Transport.AzureServiceBus;

public class ASBSTransportCustomization : TransportCustomization<AzureServiceBusTransport>
{
Expand All @@ -19,18 +22,27 @@ protected override void CustomizeTransportForMonitoringEndpoint(EndpointConfigur
protected override AzureServiceBusTransport CreateTransport(TransportSettings transportSettings, TransportTransactionMode preferredTransactionMode = TransportTransactionMode.ReceiveOnly)
{
var connectionSettings = ConnectionStringParser.Parse(transportSettings.ConnectionString);
var transport = connectionSettings.AuthenticationMethod.CreateTransportDefinition(connectionSettings);
transport.UseWebSockets = connectionSettings.UseWebSockets;

if (connectionSettings.TopicName != null)
if (!transportSettings.TryGet(out TopicTopology selectedTopology))
{
transport.Topology = TopicTopology.Single(connectionSettings.TopicName);
//Topology is pre-selected and customized only when creating transport for the primary instance
//For all other cases use the connection string to determine which topology to use
if (connectionSettings.TopicName != null)
{
#pragma warning disable CS0618 // Type or member is obsolete
selectedTopology = TopicTopology.MigrateFromNamedSingleTopic(connectionSettings.TopicName);
#pragma warning restore CS0618 // Type or member is obsolete
}
else
{
selectedTopology = TopicTopology.Default;
}
}

var transport = connectionSettings.AuthenticationMethod.CreateTransportDefinition(connectionSettings, selectedTopology);
transport.UseWebSockets = connectionSettings.UseWebSockets;
transport.EnablePartitioning = connectionSettings.EnablePartitioning;

transport.ConfigureNameShorteners();

transport.TransportTransactionMode = transport.GetSupportedTransactionModes().Contains(preferredTransactionMode) ? preferredTransactionMode : TransportTransactionMode.ReceiveOnly;

return transport;
Expand All @@ -40,6 +52,46 @@ protected override void AddTransportForPrimaryCore(IServiceCollection services,
TransportSettings transportSettings)
{
services.AddSingleton<IBrokerThroughputQuery, AzureQuery>();

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

var serviceBusRootNamespace = new SettingsRootNamespace("ServiceControl.Transport.ASBS");
if (connectionSettings.TopicName != null)
{
//Bundle name provided -> use migration topology
//Need to explicitly specific events to be published on the single topic
#pragma warning disable CS0618 // Type or member is obsolete
selectedTopology = TopicTopology.FromOptions(new MigrationTopologyOptions
#pragma warning restore CS0618 // Type or member is obsolete
{
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"
]
});
}
else if (SettingsReader.TryRead<string>(serviceBusRootNamespace, "Topology", out var topologyJson))
{
//Load topology from json
selectedTopology = TopicTopology.FromOptions(JsonSerializer.Deserialize(topologyJson, TopologyOptionsSerializationContext.Default.TopologyOptions));
}
else
{
//Default to topic-per-event topology
selectedTopology = TopicTopology.Default;
}

transportSettings.Set(selectedTopology);
}

protected override void AddTransportForMonitoringCore(IServiceCollection services, TransportSettings transportSettings)
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceControl.Transports.ASBS/AuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
public abstract class AuthenticationMethod
{
public abstract ServiceBusAdministrationClient BuildManagementClient();
public abstract AzureServiceBusTransport CreateTransportDefinition(ConnectionSettings connectionSettings);
public abstract AzureServiceBusTransport CreateTransportDefinition(ConnectionSettings connectionSettings, TopicTopology topology);
}
}
32 changes: 0 additions & 32 deletions src/ServiceControl.Transports.ASBS/Helper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SharedAccessSignatureAuthentication : AuthenticationMethod
public override ServiceBusAdministrationClient BuildManagementClient()
=> new ServiceBusAdministrationClient(ConnectionString);

public override AzureServiceBusTransport CreateTransportDefinition(ConnectionSettings connectionSettings)
=> new AzureServiceBusTransport(ConnectionString);
public override AzureServiceBusTransport CreateTransportDefinition(ConnectionSettings connectionSettings, TopicTopology topology)
=> new AzureServiceBusTransport(ConnectionString, topology);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Azure.Identity;
using Azure.Messaging.ServiceBus.Administration;
using NServiceBus;
using NServiceBus.Transport;

public class TokenCredentialAuthentication : AuthenticationMethod
{
Expand All @@ -30,9 +29,9 @@ public TokenCredentialAuthentication(string fullyQualifiedNamespace, string clie
public override ServiceBusAdministrationClient BuildManagementClient()
=> new ServiceBusAdministrationClient(FullyQualifiedNamespace, Credential);

public override AzureServiceBusTransport CreateTransportDefinition(ConnectionSettings connectionSettings)
public override AzureServiceBusTransport CreateTransportDefinition(ConnectionSettings connectionSettings, TopicTopology topology)
{
var transport = new AzureServiceBusTransport(FullyQualifiedNamespace, Credential);
var transport = new AzureServiceBusTransport(FullyQualifiedNamespace, Credential, topology);
return transport;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<!-- Private=false & ExcludeAssets=runtime prevent repeatedly including binary dependencies of ServiceControl.Transports in each transport directory -->
<ProjectReference Include="..\ServiceControl.Configuration\ServiceControl.Configuration.csproj" Private="false" ExcludeAssets="runtime" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="NServiceBus" />
Expand Down