From de5897682256fc87a071ad9f2ac9648dfcea6e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Fri, 5 May 2023 13:51:38 +0200 Subject: [PATCH] Make monitoring not need timeout infrastructure on MSMQ (#3504) (#3510) * Add test for service control * Centralize default endpoint configuration * Update approvals for transport configuration * Remove unneeded test config * Use unique name for test error queue * Use sanitizer for ASQ * Move sanitization to ConfigureTransport method * Call CreateTestQueue instead of ProvisionQueues * Remove unused feature configuration code * Use CreateTestQueue instead of ProvisionQueues * Make queue creation explicit in tests * Remove UsePersistence call * Use explicit persistence in tests --------- Co-authored-by: williambza --- .../Infrastructure/When_instance_is_setup.cs | 6 +-- .../Infrastructure/NServiceBusFactory.cs | 8 --- ...BEndpointTopologyTransportCustomization.cs | 6 +-- ...orwardingTopologyTransportCustomization.cs | 9 ++-- .../ASBSTransportCustomization.cs | 9 ++-- .../ASQTransportCustomization.cs | 11 ++-- .../LearningTransportCustomization.cs | 8 ++- .../MsmqTransportCustomization.cs | 9 ++-- ...nventionalRoutingTransportCustomization.cs | 9 ++-- ...itMQDirectRoutingTransportCustomization.cs | 9 ++-- .../SQSTransportCustomization.cs | 6 +-- .../SqlServerTransportCustomization.cs | 9 ++-- ...ovals.ServiceControlTransport.approved.txt | 10 ++-- .../BasicEndpointSetup.cs | 4 +- ...onfigTests.cs => SendOnlyEndpointTests.cs} | 18 +------ .../ServiceControlEndpointTests.cs | 52 +++++++++++++++++++ .../ServiceControlMonitoringEndpointTests.cs | 52 +++++++++++++++++++ .../TransportCustomization.cs | 42 +++++++++++++-- .../Infrastructure/NServiceBusFactory.cs | 8 --- 19 files changed, 190 insertions(+), 95 deletions(-) rename src/ServiceControl.Transports.Tests/{NServiceBusConfigTests.cs => SendOnlyEndpointTests.cs} (60%) create mode 100644 src/ServiceControl.Transports.Tests/ServiceControlEndpointTests.cs create mode 100644 src/ServiceControl.Transports.Tests/ServiceControlMonitoringEndpointTests.cs diff --git a/src/ServiceControl.Audit.UnitTests/Infrastructure/When_instance_is_setup.cs b/src/ServiceControl.Audit.UnitTests/Infrastructure/When_instance_is_setup.cs index 82363344cc..d8ab2def4e 100644 --- a/src/ServiceControl.Audit.UnitTests/Infrastructure/When_instance_is_setup.cs +++ b/src/ServiceControl.Audit.UnitTests/Infrastructure/When_instance_is_setup.cs @@ -58,9 +58,9 @@ public override Task ProvisionQueues(string username, TransportSettings transpor public override IProvideQueueLength CreateQueueLengthProvider() => throw new System.NotImplementedException(); public override void CustomizeForReturnToSenderIngestion(RawEndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); protected override void CustomizeRawSendOnlyEndpoint(RawEndpointConfiguration endpointConfiguration, TransportSettings transportSettings) => throw new System.NotImplementedException(); } diff --git a/src/ServiceControl.Audit/Infrastructure/NServiceBusFactory.cs b/src/ServiceControl.Audit/Infrastructure/NServiceBusFactory.cs index 758a1817aa..b6c6cab3d3 100644 --- a/src/ServiceControl.Audit/Infrastructure/NServiceBusFactory.cs +++ b/src/ServiceControl.Audit/Infrastructure/NServiceBusFactory.cs @@ -7,7 +7,6 @@ namespace ServiceControl.Audit.Infrastructure using Contracts.MessageFailures; using NServiceBus; using NServiceBus.Configuration.AdvancedExtensibility; - using NServiceBus.Features; using Settings; using Transports; @@ -27,11 +26,7 @@ public static void Configure(Settings.Settings settings, TransportCustomization configuration.GetSettings().Set("ServiceControl.Settings", settings); - configuration.SendOnly(); - transportCustomization.CustomizeSendOnlyEndpoint(configuration, transportSettings); - //DisablePublishing API is available only on TransportExtensions for transports that implement IMessageDrivenPubSub so we need to set settings directly - configuration.GetSettings().Set("NServiceBus.PublishSubscribe.EnablePublishing", false); var serviceControlLogicalQueue = settings.ServiceControlQueueAddress; if (!string.IsNullOrWhiteSpace(serviceControlLogicalQueue)) @@ -54,9 +49,6 @@ public static void Configure(Settings.Settings settings, TransportCustomization configuration.GetSettings().Set(loggingSettings); configuration.SetDiagnosticsPath(loggingSettings.LogPath); - // sagas are not auto-disabled for send-only endpoints - configuration.DisableFeature(); - configuration.UseSerialization(); configuration.Conventions().DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t) || IsExternalContract(t)); diff --git a/src/ServiceControl.Transports.ASB/ASBEndpointTopologyTransportCustomization.cs b/src/ServiceControl.Transports.ASB/ASBEndpointTopologyTransportCustomization.cs index 099c754303..be5c4cbaf3 100644 --- a/src/ServiceControl.Transports.ASB/ASBEndpointTopologyTransportCustomization.cs +++ b/src/ServiceControl.Transports.ASB/ASBEndpointTopologyTransportCustomization.cs @@ -15,7 +15,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } @@ -30,12 +30,12 @@ protected override void CustomizeRawSendOnlyEndpoint(RawEndpointConfiguration en CustomizeRawEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.SendsAtomicWithReceive); } diff --git a/src/ServiceControl.Transports.ASB/ASBForwardingTopologyTransportCustomization.cs b/src/ServiceControl.Transports.ASB/ASBForwardingTopologyTransportCustomization.cs index d6dbb11730..703c33e0ab 100644 --- a/src/ServiceControl.Transports.ASB/ASBForwardingTopologyTransportCustomization.cs +++ b/src/ServiceControl.Transports.ASB/ASBForwardingTopologyTransportCustomization.cs @@ -1,10 +1,7 @@ namespace ServiceControl.Transports.ASB { - using System; - using System.Threading.Tasks; using NServiceBus; using NServiceBus.Raw; - using NServiceBus.Transport; public class ASBForwardingTopologyTransportCustomization : TransportCustomization { @@ -18,7 +15,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } @@ -33,12 +30,12 @@ protected override void CustomizeRawSendOnlyEndpoint(RawEndpointConfiguration en CustomizeRawEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.SendsAtomicWithReceive); } diff --git a/src/ServiceControl.Transports.ASBS/ASBSTransportCustomization.cs b/src/ServiceControl.Transports.ASBS/ASBSTransportCustomization.cs index 6fc70d8a89..9c5c35819d 100644 --- a/src/ServiceControl.Transports.ASBS/ASBSTransportCustomization.cs +++ b/src/ServiceControl.Transports.ASBS/ASBSTransportCustomization.cs @@ -1,10 +1,7 @@ namespace ServiceControl.Transports.ASBS { - using System; - using System.Threading.Tasks; using NServiceBus; using NServiceBus.Raw; - using NServiceBus.Transport; public class ASBSTransportCustomization : TransportCustomization { @@ -15,7 +12,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeEndpoint(transport, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport(); @@ -29,7 +26,7 @@ public override void CustomizeForReturnToSenderIngestion(RawEndpointConfiguratio CustomizeEndpoint(transport, transportSettings, TransportTransactionMode.SendsAtomicWithReceive); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport(); @@ -43,7 +40,7 @@ protected override void CustomizeRawSendOnlyEndpoint(RawEndpointConfiguration en CustomizeEndpoint(transport, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport(); diff --git a/src/ServiceControl.Transports.ASQ/ASQTransportCustomization.cs b/src/ServiceControl.Transports.ASQ/ASQTransportCustomization.cs index 7303e9543f..0f17b42632 100644 --- a/src/ServiceControl.Transports.ASQ/ASQTransportCustomization.cs +++ b/src/ServiceControl.Transports.ASQ/ASQTransportCustomization.cs @@ -2,9 +2,7 @@ { using NServiceBus; using NServiceBus.Raw; - using NServiceBus.Transport; using System; - using System.Threading.Tasks; public class ASQTransportCustomization : TransportCustomization { @@ -14,7 +12,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings); } @@ -24,7 +22,7 @@ public override void CustomizeForReturnToSenderIngestion(RawEndpointConfiguratio CustomizeRawEndpoint(endpointConfiguration, transportSettings); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = CustomizeEndpoint(endpointConfiguration, transportSettings); transport.EnableMessageDrivenPubSubCompatibilityMode(); @@ -35,7 +33,7 @@ protected override void CustomizeRawSendOnlyEndpoint(RawEndpointConfiguration en CustomizeRawEndpoint(endpointConfiguration, transportSettings); } - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings); //Do not ConfigurePubSub for send-only endpoint @@ -44,6 +42,7 @@ public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointCon static TransportExtensions CustomizeEndpoint(EndpointConfiguration endpointConfig, TransportSettings transportSettings) { var transport = endpointConfig.UseTransport(); + ConfigureTransport(transport, transportSettings); return transport; } @@ -60,9 +59,9 @@ static void ConfigureTransport(TransportExtensions t var connectionString = transportSettings.ConnectionString .RemoveCustomConnectionStringParts(out var subscriptionTableName); - transport.SanitizeQueueNamesWith(BackwardsCompatibleQueueNameSanitizer.Sanitize); transport.Transactions(TransportTransactionMode.ReceiveOnly); transport.ConnectionString(connectionString); + transport.SanitizeQueueNamesWith(BackwardsCompatibleQueueNameSanitizer.Sanitize); if (!string.IsNullOrEmpty(subscriptionTableName)) { diff --git a/src/ServiceControl.Transports.Learning/LearningTransportCustomization.cs b/src/ServiceControl.Transports.Learning/LearningTransportCustomization.cs index d456d542e8..176047551c 100644 --- a/src/ServiceControl.Transports.Learning/LearningTransportCustomization.cs +++ b/src/ServiceControl.Transports.Learning/LearningTransportCustomization.cs @@ -1,20 +1,18 @@ namespace ServiceControl.Transports.Learning { using System; - using System.Threading.Tasks; using LearningTransport; using NServiceBus; using NServiceBus.Raw; - using NServiceBus.Transport; public class LearningTransportCustomization : TransportCustomization { - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.SendsAtomicWithReceive); } @@ -29,7 +27,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } diff --git a/src/ServiceControl.Transports.Msmq/MsmqTransportCustomization.cs b/src/ServiceControl.Transports.Msmq/MsmqTransportCustomization.cs index 79eb4cc354..fe837c62ae 100644 --- a/src/ServiceControl.Transports.Msmq/MsmqTransportCustomization.cs +++ b/src/ServiceControl.Transports.Msmq/MsmqTransportCustomization.cs @@ -1,19 +1,16 @@ namespace ServiceControl.Transports.Msmq { - using System; - using System.Threading.Tasks; using NServiceBus; using NServiceBus.Raw; - using NServiceBus.Transport; public class MsmqTransportCustomization : TransportCustomization { - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, TransportTransactionMode.SendsAtomicWithReceive); } @@ -29,7 +26,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp transport.IgnoreIncomingTimeToBeReceivedHeaders(); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, TransportTransactionMode.ReceiveOnly); } diff --git a/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs b/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs index 1967a4d2b9..0fb42bd93b 100644 --- a/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs +++ b/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs @@ -1,10 +1,7 @@ namespace ServiceControl.Transports.RabbitMQ { - using System.Threading.Tasks; - using System; using NServiceBus; using NServiceBus.Raw; - using NServiceBus.Transport; public abstract class RabbitMQConventionalRoutingTransportCustomization : TransportCustomization { @@ -15,12 +12,12 @@ protected RabbitMQConventionalRoutingTransportCustomization(QueueType queueType) this.queueType = queueType; } - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, queueType); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, queueType); } @@ -35,7 +32,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings, queueType); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, queueType); } diff --git a/src/ServiceControl.Transports.RabbitMQ/RabbitMQDirectRoutingTransportCustomization.cs b/src/ServiceControl.Transports.RabbitMQ/RabbitMQDirectRoutingTransportCustomization.cs index 38a68b2bae..ee04df33c6 100644 --- a/src/ServiceControl.Transports.RabbitMQ/RabbitMQDirectRoutingTransportCustomization.cs +++ b/src/ServiceControl.Transports.RabbitMQ/RabbitMQDirectRoutingTransportCustomization.cs @@ -1,10 +1,7 @@ namespace ServiceControl.Transports.RabbitMQ { - using System.Threading.Tasks; - using System; using NServiceBus; using NServiceBus.Raw; - using NServiceBus.Transport; public abstract class RabbitMQDirectRoutingTransportCustomization : TransportCustomization { @@ -15,12 +12,12 @@ protected RabbitMQDirectRoutingTransportCustomization(QueueType queueType) this.queueType = queueType; } - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, queueType); } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, queueType); } @@ -35,7 +32,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings, queueType); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, queueType); } diff --git a/src/ServiceControl.Transports.SQS/SQSTransportCustomization.cs b/src/ServiceControl.Transports.SQS/SQSTransportCustomization.cs index 85d2b8aeb2..faf17448f3 100644 --- a/src/ServiceControl.Transports.SQS/SQSTransportCustomization.cs +++ b/src/ServiceControl.Transports.SQS/SQSTransportCustomization.cs @@ -16,14 +16,14 @@ public class SQSTransportCustomization : TransportCustomization { - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport(); ConfigureTransport(transport, transportSettings); //Do not ConfigurePubSub for send-only endpoint } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport(); ConfigureTransport(transport, transportSettings); @@ -40,7 +40,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport(); ConfigureTransport(transport, transportSettings); diff --git a/src/ServiceControl.Transports.SqlServer/SqlServerTransportCustomization.cs b/src/ServiceControl.Transports.SqlServer/SqlServerTransportCustomization.cs index fd2089247d..97bd1b7f0c 100644 --- a/src/ServiceControl.Transports.SqlServer/SqlServerTransportCustomization.cs +++ b/src/ServiceControl.Transports.SqlServer/SqlServerTransportCustomization.cs @@ -1,22 +1,19 @@ namespace ServiceControl.Transports.SqlServer { - using System; - using System.Threading.Tasks; using NServiceBus; using NServiceBus.Configuration.AdvancedExtensibility; using NServiceBus.Logging; using NServiceBus.Raw; - using NServiceBus.Transport; public class SqlServerTransportCustomization : TransportCustomization { - public override void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); //Do not EnableMessageDrivenPubSubCompatibilityMode for send-only endpoint } - public override void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.SendsAtomicWithReceive); transport.EnableMessageDrivenPubSubCompatibilityMode(); @@ -32,7 +29,7 @@ protected override void CustomizeForQueueIngestion(RawEndpointConfiguration endp CustomizeRawEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } - public override void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + protected override void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { CustomizeEndpoint(endpointConfiguration, transportSettings, TransportTransactionMode.ReceiveOnly); } diff --git a/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt b/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt index 8014906430..e3967766c9 100644 --- a/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt +++ b/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt @@ -31,13 +31,17 @@ namespace ServiceControl.Transports public abstract class TransportCustomization { protected TransportCustomization() { } + protected void ConfigureDefaultEndpointSettings(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings) { } public abstract ServiceControl.Transports.IProvideQueueLength CreateQueueLengthProvider(); protected abstract void CustomizeForQueueIngestion(NServiceBus.Raw.RawEndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); public abstract void CustomizeForReturnToSenderIngestion(NServiceBus.Raw.RawEndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); - public abstract void CustomizeMonitoringEndpoint(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); + public void CustomizeMonitoringEndpoint(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings) { } protected abstract void CustomizeRawSendOnlyEndpoint(NServiceBus.Raw.RawEndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); - public abstract void CustomizeSendOnlyEndpoint(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); - public abstract void CustomizeServiceControlEndpoint(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); + public void CustomizeSendOnlyEndpoint(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings) { } + public void CustomizeServiceControlEndpoint(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings) { } + protected abstract void CustomizeTransportSpecificMonitoringEndpointSettings(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); + protected abstract void CustomizeTransportSpecificSendOnlyEndpointSettings(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); + protected abstract void CustomizeTransportSpecificServiceControlEndpointSettings(NServiceBus.EndpointConfiguration endpointConfiguration, ServiceControl.Transports.TransportSettings transportSettings); public System.Threading.Tasks.Task InitializeDispatcher(string name, ServiceControl.Transports.TransportSettings transportSettings) { } public System.Threading.Tasks.Task InitializeQueueIngestor(string queueName, ServiceControl.Transports.TransportSettings transportSettings, System.Func onMessage, System.Func> onError, System.Func onCriticalError) { } public virtual System.Threading.Tasks.Task ProvisionQueues(string username, ServiceControl.Transports.TransportSettings transportSettings, System.Collections.Generic.IEnumerable additionalQueues) { } diff --git a/src/ServiceControl.Transports.Tests/BasicEndpointSetup.cs b/src/ServiceControl.Transports.Tests/BasicEndpointSetup.cs index 34225918de..f479654cbc 100644 --- a/src/ServiceControl.Transports.Tests/BasicEndpointSetup.cs +++ b/src/ServiceControl.Transports.Tests/BasicEndpointSetup.cs @@ -15,7 +15,9 @@ public Task GetConfiguration(RunDescriptor runDescriptor, var endpointConfiguration = new EndpointConfiguration(endpointCustomization.EndpointName); endpointConfiguration.TypesToIncludeInScan(typesToInclude); - endpointConfiguration.EnableInstallers(); + + // we don't use installers + //endpointConfiguration.EnableInstallers(); endpointConfiguration.UseSerialization(); endpointConfiguration.RegisterComponentsAndInheritanceHierarchy(runDescriptor); diff --git a/src/ServiceControl.Transports.Tests/NServiceBusConfigTests.cs b/src/ServiceControl.Transports.Tests/SendOnlyEndpointTests.cs similarity index 60% rename from src/ServiceControl.Transports.Tests/NServiceBusConfigTests.cs rename to src/ServiceControl.Transports.Tests/SendOnlyEndpointTests.cs index 67f6213f36..864cc9175a 100644 --- a/src/ServiceControl.Transports.Tests/NServiceBusConfigTests.cs +++ b/src/ServiceControl.Transports.Tests/SendOnlyEndpointTests.cs @@ -1,13 +1,11 @@ namespace ServiceControl.Transport.Tests { using System.Threading.Tasks; - using NServiceBus; using NServiceBus.AcceptanceTesting; - using NServiceBus.Configuration.AdvancedExtensibility; using NUnit.Framework; using ServiceControl.Transports; - class NServiceBusConfigTests : TransportTestFixture + class SendOnlyEndpointTests : TransportTestFixture { [Test] public async Task Should_be_able_to_create_send_only_endpoint() @@ -31,26 +29,14 @@ public async Task Should_be_able_to_create_send_only_endpoint() public class Context : ScenarioContext { - public bool SendingEndpointGotResponse { get; set; } - public string ReplyToAddress { get; set; } } public class SendOnlyEndpoint : EndpointConfigurationBuilder { public SendOnlyEndpoint() { - EndpointSetup(c => - { - c.SendOnly(); - - //DisablePublishing API is available only on TransportExtensions for transports that implement IMessageDrivenPubSub so we need to set settings directly - c.GetSettings().Set("NServiceBus.PublishSubscribe.EnablePublishing", false); - }); + EndpointSetup(); } } - - public class MyMessage : IMessage - { - } } } \ No newline at end of file diff --git a/src/ServiceControl.Transports.Tests/ServiceControlEndpointTests.cs b/src/ServiceControl.Transports.Tests/ServiceControlEndpointTests.cs new file mode 100644 index 0000000000..0300f84539 --- /dev/null +++ b/src/ServiceControl.Transports.Tests/ServiceControlEndpointTests.cs @@ -0,0 +1,52 @@ +namespace ServiceControl.Transport.Tests +{ + using System.Collections.Generic; + using System.Security.Principal; + using System.Threading.Tasks; + using NServiceBus; + using NServiceBus.AcceptanceTesting; + using NUnit.Framework; + using ServiceControl.Transports; + + class ServiceControlEndpointTests : TransportTestFixture + { + [Test] + public async Task Should_configure_endpoint() + { + var endpointName = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(ServiceControlEndpoint)); + var transportSettings = new TransportSettings + { + ConnectionString = configuration.ConnectionString, + MaxConcurrency = 1, + EndpointName = endpointName + }; + + await configuration.TransportCustomization.ProvisionQueues(WindowsIdentity.GetCurrent().Name, transportSettings, new List()); + + var ctx = await Scenario.Define() + .WithEndpoint(c => c.CustomConfig(ec => + { + configuration.TransportCustomization.CustomizeServiceControlEndpoint(ec, transportSettings); + })) + .Done(c => c.EndpointsStarted) + .Run(); + + Assert.IsTrue(ctx.EndpointsStarted); + } + + public class Context : ScenarioContext + { + } + + public class ServiceControlEndpoint : EndpointConfigurationBuilder + { + public ServiceControlEndpoint() + { + EndpointSetup(c => + { + c.UsePersistence(); + }); + } + } + } +} \ No newline at end of file diff --git a/src/ServiceControl.Transports.Tests/ServiceControlMonitoringEndpointTests.cs b/src/ServiceControl.Transports.Tests/ServiceControlMonitoringEndpointTests.cs new file mode 100644 index 0000000000..95c1c59f69 --- /dev/null +++ b/src/ServiceControl.Transports.Tests/ServiceControlMonitoringEndpointTests.cs @@ -0,0 +1,52 @@ +namespace ServiceControl.Transport.Tests +{ + using System.Collections.Generic; + using System.Security.Principal; + using System.Threading.Tasks; + using NServiceBus; + using NServiceBus.AcceptanceTesting; + using NUnit.Framework; + using ServiceControl.Transports; + + class ServiceControlMonitoringEndpointTests : TransportTestFixture + { + [Test] + public async Task Should_configure_monitoring_endpoint() + { + var endpointName = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(ServiceControlEndpoint)); + var transportSettings = new TransportSettings + { + ConnectionString = configuration.ConnectionString, + MaxConcurrency = 1, + EndpointName = endpointName + }; + + await configuration.TransportCustomization.ProvisionQueues(WindowsIdentity.GetCurrent().Name, transportSettings, new List()); + + var ctx = await Scenario.Define() + .WithEndpoint(c => c.CustomConfig(ec => + { + configuration.TransportCustomization.CustomizeMonitoringEndpoint(ec, transportSettings); + })) + .Done(c => c.EndpointsStarted) + .Run(); + + Assert.IsTrue(ctx.EndpointsStarted); + } + + public class Context : ScenarioContext + { + } + + public class ServiceControlEndpoint : EndpointConfigurationBuilder + { + public ServiceControlEndpoint() + { + EndpointSetup(c => + { + c.UsePersistence(); + }); + } + } + } +} \ No newline at end of file diff --git a/src/ServiceControl.Transports/TransportCustomization.cs b/src/ServiceControl.Transports/TransportCustomization.cs index e9c56016c4..da0480ea0d 100644 --- a/src/ServiceControl.Transports/TransportCustomization.cs +++ b/src/ServiceControl.Transports/TransportCustomization.cs @@ -2,22 +2,58 @@ { using System; using System.Collections.Generic; + using System.Configuration; using System.Linq; using System.Threading.Tasks; using NServiceBus; + using NServiceBus.Configuration.AdvancedExtensibility; + using NServiceBus.Features; using NServiceBus.Raw; using NServiceBus.Transport; public abstract class TransportCustomization { - public abstract void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings); + protected abstract void CustomizeTransportSpecificServiceControlEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings); - public abstract void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings); + protected abstract void CustomizeTransportSpecificSendOnlyEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings); - public abstract void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings); + protected abstract void CustomizeTransportSpecificMonitoringEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings); public abstract void CustomizeForReturnToSenderIngestion(RawEndpointConfiguration endpointConfiguration, TransportSettings transportSettings); + public void CustomizeServiceControlEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + { + ConfigureDefaultEndpointSettings(endpointConfiguration, transportSettings); + CustomizeTransportSpecificServiceControlEndpointSettings(endpointConfiguration, transportSettings); + } + + public void CustomizeSendOnlyEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + { + ConfigureDefaultEndpointSettings(endpointConfiguration, transportSettings); + CustomizeTransportSpecificSendOnlyEndpointSettings(endpointConfiguration, transportSettings); + + endpointConfiguration.SendOnly(); + + //DisablePublishing API is available only on TransportExtensions for transports that implement IMessageDrivenPubSub so we need to set settings directly + endpointConfiguration.GetSettings().Set("NServiceBus.PublishSubscribe.EnablePublishing", false); + } + + public void CustomizeMonitoringEndpoint(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + { + ConfigureDefaultEndpointSettings(endpointConfiguration, transportSettings); + CustomizeTransportSpecificMonitoringEndpointSettings(endpointConfiguration, transportSettings); + } + + protected void ConfigureDefaultEndpointSettings(EndpointConfiguration endpointConfiguration, TransportSettings transportSettings) + { + endpointConfiguration.DisableFeature(); + endpointConfiguration.DisableFeature(); + endpointConfiguration.DisableFeature(); + endpointConfiguration.DisableFeature(); + endpointConfiguration.DisableFeature(); + endpointConfiguration.SendFailedMessagesTo(transportSettings.ErrorQueue); + } + public abstract IProvideQueueLength CreateQueueLengthProvider(); public async Task InitializeDispatcher(string name, TransportSettings transportSettings) diff --git a/src/ServiceControl/Infrastructure/NServiceBusFactory.cs b/src/ServiceControl/Infrastructure/NServiceBusFactory.cs index 669fe0ee55..605bac8597 100644 --- a/src/ServiceControl/Infrastructure/NServiceBusFactory.cs +++ b/src/ServiceControl/Infrastructure/NServiceBusFactory.cs @@ -3,7 +3,6 @@ namespace ServiceBus.Management.Infrastructure using System; using NServiceBus; using NServiceBus.Configuration.AdvancedExtensibility; - using NServiceBus.Features; using ServiceControl.ExternalIntegrations; using ServiceControl.Infrastructure.RavenDB.Subscriptions; using ServiceControl.Notifications.Email; @@ -29,13 +28,6 @@ public static void Configure(Settings.Settings settings, TransportCustomization configuration.GetSettings().Set(loggingSettings); configuration.SetDiagnosticsPath(loggingSettings.LogPath); - // Disable Auditing for the service control endpoint - configuration.DisableFeature(); - configuration.DisableFeature(); - configuration.DisableFeature(); - configuration.DisableFeature(); - configuration.DisableFeature(); - if (settings.DisableExternalIntegrationsPublishing) { configuration.DisableFeature();