/
ASQTransportCustomization.cs
45 lines (35 loc) · 2.3 KB
/
ASQTransportCustomization.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace ServiceControl.Transports.ASQ
{
using System;
using System.Linq;
using NServiceBus;
using NServiceBus.Configuration.AdvancedExtensibility;
public class ASQTransportCustomization : TransportCustomization<AzureStorageQueueTransport>
{
protected override void CustomizeTransportForPrimaryEndpoint(EndpointConfiguration endpointConfiguration, AzureStorageQueueTransport transportDefinition, TransportSettings transportSettings)
{
var routing = new RoutingSettings(endpointConfiguration.GetSettings());
routing.EnableMessageDrivenPubSubCompatibilityMode();
}
//Do not ConfigurePubSub for send-only endpoint
protected override void CustomizeTransportForAuditEndpoint(EndpointConfiguration endpointConfiguration, AzureStorageQueueTransport transportDefinition, TransportSettings transportSettings) { }
protected override void CustomizeTransportForMonitoringEndpoint(EndpointConfiguration endpointConfiguration, AzureStorageQueueTransport transportDefinition, TransportSettings transportSettings) { }
public override IProvideQueueLength CreateQueueLengthProvider() => new QueueLengthProvider();
protected override AzureStorageQueueTransport CreateTransport(TransportSettings transportSettings, TransportTransactionMode preferredTransactionMode = TransportTransactionMode.ReceiveOnly)
{
var connectionString = transportSettings.ConnectionString.RemoveCustomConnectionStringParts(out var subscriptionTableName);
var transport = new AzureStorageQueueTransport(connectionString, useNativeDelayedDeliveries: false)
{
QueueNameSanitizer = BackwardsCompatibleQueueNameSanitizer.Sanitize,
MessageInvisibleTime = TimeSpan.FromMinutes(1)
};
if (!string.IsNullOrEmpty(subscriptionTableName))
{
transport.Subscriptions.SubscriptionTableName = subscriptionTableName;
}
transport.MessageWrapperSerializationDefinition = new NewtonsoftJsonSerializer();
transport.TransportTransactionMode = transport.GetSupportedTransactionModes().Contains(preferredTransactionMode) ? preferredTransactionMode : TransportTransactionMode.ReceiveOnly;
return transport;
}
}
}