public RoutingComponent(SettingsHolder settings) { this.settings = settings; // use GetOrCreate to use of instances already created during EndpointConfiguration. UnicastRoutingTable = settings.GetOrCreate <UnicastRoutingTable>(); DistributionPolicy = settings.GetOrCreate <DistributionPolicy>(); EndpointInstances = settings.GetOrCreate <EndpointInstances>(); Publishers = settings.GetOrCreate <Publishers>(); }
internal SqlServerTransportInfrastructure(string catalog, SettingsHolder settings, string connectionString, Func <string> localAddress, Func <LogicalAddress> logicalAddress, bool isEncrypted) { this.settings = settings; this.connectionString = connectionString; this.localAddress = localAddress; this.logicalAddress = logicalAddress; this.isEncrypted = isEncrypted; if (settings.HasSetting(SettingsKeys.DisableNativePubSub)) { OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Unicast, OutboundRoutingType.Unicast); } else { OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Multicast, OutboundRoutingType.Unicast); } settings.TryGet(SettingsKeys.DefaultSchemaSettingsKey, out string defaultSchemaOverride); var queueSchemaSettings = settings.GetOrDefault <QueueSchemaAndCatalogSettings>(); addressTranslator = new QueueAddressTranslator(catalog, "dbo", defaultSchemaOverride, queueSchemaSettings); tableBasedQueueCache = new TableBasedQueueCache(addressTranslator, !isEncrypted); connectionFactory = CreateConnectionFactory(); //Configure the schema and catalog for logical endpoint-based routing var schemaAndCatalogSettings = settings.GetOrCreate <EndpointSchemaAndCatalogSettings>(); settings.GetOrCreate <EndpointInstances>().AddOrReplaceInstances("SqlServer", schemaAndCatalogSettings.ToEndpointInstances()); var pubSubSettings = settings.GetOrCreate <SubscriptionSettings>(); var subscriptionTableName = pubSubSettings.SubscriptionTable.Qualify(defaultSchemaOverride ?? "dbo", catalog); // necessary evil for acceptance tests if (settings.TryGet <Action <string> >(SettingsKeys.SubscriptionTableQuotedQualifiedNameSetter, out var action)) { action(subscriptionTableName.QuotedQualifiedName); } subscriptionStore = new PolymorphicSubscriptionStore(new SubscriptionTable(subscriptionTableName.QuotedQualifiedName, connectionFactory)); var timeToCacheSubscriptions = pubSubSettings.TimeToCacheSubscriptions; if (timeToCacheSubscriptions.HasValue) { subscriptionStore = new CachedSubscriptionStore(subscriptionStore, timeToCacheSubscriptions.Value); } var subscriptionTableCreator = new SubscriptionTableCreator(subscriptionTableName, connectionFactory); settings.Set(subscriptionTableCreator); }
public TransportConfigurationResult Configure(SettingsHolder settings, TransportTransactionMode transactionMode) { LogManager.UseFactory(new ConsoleLoggerFactory()); if (settings.TryGet <MessageMetadataRegistry>(out var registry) == false) { const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance; var conventions = settings.GetOrCreate <Conventions>(); registry = (MessageMetadataRegistry)Activator.CreateInstance(typeof(MessageMetadataRegistry), flags, null, new object[] { new Func <Type, bool>(t => conventions.IsMessageType(t)) }, CultureInfo.InvariantCulture); settings.Set(registry); } var methodName = TestContext.CurrentContext.Test.MethodName; if (methodName == nameof(When_on_error_throws.Should_reinvoke_on_error_with_original_exception)) { throw new IgnoreException("ASQ uses a circuit breaker that is triggered after specific period of time. Critical errors are not reported immediately"); } settings.Set(AzureStorageQueueTransport.SerializerSettingsKey, Tuple.Create <SerializationDefinition, SettingsHolder>(new XmlSerializer(), settings)); var transportExtension = new TransportExtensions <AzureStorageQueueTransport>(settings); transportExtension.SanitizeQueueNamesWith(BackwardsCompatibleQueueNameSanitizerForTests.Sanitize); return(new TransportConfigurationResult { TransportInfrastructure = new AzureStorageQueueTransport().Initialize(settings, Testing.Utillities.GetEnvConfiguredConnectionString()), PurgeInputQueueOnStartup = false }); }
internal SqlServerTransportInfrastructure(string catalog, SettingsHolder settings, string connectionString, Func <string> localAddress, Func <LogicalAddress> logicalAddress) { this.settings = settings; this.connectionString = connectionString; this.localAddress = localAddress; this.logicalAddress = logicalAddress; if (settings.HasSetting(SettingsKeys.DisableNativePubSub)) { OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Unicast, OutboundRoutingType.Unicast); } else { OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Multicast, OutboundRoutingType.Unicast); } settings.TryGet(SettingsKeys.DefaultSchemaSettingsKey, out string defaultSchemaOverride); var queueSchemaSettings = settings.GetOrDefault <QueueSchemaAndCatalogSettings>(); addressTranslator = new QueueAddressTranslator(catalog, "dbo", defaultSchemaOverride, queueSchemaSettings); tableBasedQueueCache = new TableBasedQueueCache(addressTranslator); connectionFactory = CreateConnectionFactory(); //Configure the schema and catalog for logical endpoint-based routing var schemaAndCatalogSettings = settings.GetOrCreate <EndpointSchemaAndCatalogSettings>(); settings.GetOrCreate <EndpointInstances>().AddOrReplaceInstances("SqlServer", schemaAndCatalogSettings.ToEndpointInstances()); //Needs to be invoked here and not when configuring the receiving infrastructure because the EnableMigrationMode flag has to be set up before feature component is initialized. HandleTimeoutManagerCompatibilityMode(); var pubSubSettings = settings.GetOrCreate <SubscriptionSettings>(); var subscriptionTableName = pubSubSettings.SubscriptionTable.Qualify(defaultSchemaOverride ?? "dbo", catalog); subscriptionStore = new PolymorphicSubscriptionStore(new SubscriptionTable(subscriptionTableName.QuotedQualifiedName, connectionFactory)); var timeToCacheSubscriptions = pubSubSettings.TimeToCacheSubscriptions; if (timeToCacheSubscriptions.HasValue) { subscriptionStore = new CachedSubscriptionStore(subscriptionStore, timeToCacheSubscriptions.Value); } var subscriptionTableCreator = new SubscriptionTableCreator(subscriptionTableName, connectionFactory); settings.Set(subscriptionTableCreator); }
internal SqlServerTransportInfrastructure(QueueAddressParser addressParser, SettingsHolder settings, string connectionString) { this.addressParser = addressParser; this.settings = settings; this.connectionString = connectionString; endpointSchemasSettings = settings.GetOrCreate <EndpointSchemasSettings>(); //HINT: this flag indicates that user need to explicitly turn outbox in configuration. RequireOutboxConsent = true; }
public override TransportInfrastructure Initialize(SettingsHolder settings, string connectionString) { settings.GetOrCreate <StartUpSequence>().Add($"{nameof(TransportDefinition)}.{nameof(Initialize)}"); if (settings.TryGet <Action <ReadOnlySettings> >("FakeTransport.AssertSettings", out var assertion)) { assertion(settings); } return(new FakeTransportInfrastructure(settings)); }
static List <Type> GetAllowedCoreTypes(SettingsHolder settings) { var assemblyScannerSettings = settings.GetOrCreate <AssemblyScannerConfiguration>(); var assemblyScanner = new AssemblyScanner(Assembly.GetExecutingAssembly()) { AssembliesToSkip = assemblyScannerSettings.ExcludedAssemblies, TypesToSkip = assemblyScannerSettings.ExcludedTypes, ScanNestedDirectories = assemblyScannerSettings.ScanAssembliesInNestedDirectories, ThrowExceptions = assemblyScannerSettings.ThrowExceptions, ScanAppDomainAssemblies = assemblyScannerSettings.ScanAppDomainAssemblies }; return(Scan(assemblyScanner, settings)); }
internal SqlServerTransportInfrastructure(QueueAddressTranslator addressTranslator, SettingsHolder settings, string connectionString) { this.addressTranslator = addressTranslator; this.settings = settings; this.connectionString = connectionString; schemaAndCatalogSettings = settings.GetOrCreate <EndpointSchemaAndCatalogSettings>(); delayedDeliverySettings = settings.GetOrDefault <DelayedDeliverySettings>(); var timeoutManagerFeatureDisabled = settings.GetOrDefault <FeatureState>(typeof(TimeoutManager).FullName) == FeatureState.Disabled; if (delayedDeliverySettings != null && timeoutManagerFeatureDisabled) { delayedDeliverySettings.DisableTimeoutManagerCompatibility(); } //HINT: this flag indicates that user need to explicitly turn outbox in configuration. RequireOutboxConsent = true; }
protected AzureServiceBusTransportInfrastructure(SettingsHolder settings) { TransactionMode = settings.SupportedTransactionMode(); Settings = settings; TopologySettings = settings.GetOrCreate <TopologySettings>(); var individualizationStrategyType = (Type)Settings.Get(WellKnownConfigurationKeys.Topology.Addressing.Individualization.Strategy); individualization = individualizationStrategyType.CreateInstance <IIndividualizationStrategy>(Settings); var compositionStrategyType = (Type)Settings.Get(WellKnownConfigurationKeys.Topology.Addressing.Composition.Strategy); var compositionStrategy = compositionStrategyType.CreateInstance <ICompositionStrategy>(Settings); var sanitizationStrategyType = (Type)Settings.Get(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.Strategy); var sanitizationStrategy = sanitizationStrategyType.CreateInstance <ISanitizationStrategy>(Settings); addressingLogic = new AddressingLogic(sanitizationStrategy, compositionStrategy); }
public void Should_not_throw_exception_when_serializer_was_set() { var settings = new SettingsHolder(); const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance; var conventions = settings.GetOrCreate <Conventions>(); var registry = (MessageMetadataRegistry)Activator.CreateInstance(typeof(MessageMetadataRegistry), flags, null, new object[] { new Func <Type, bool>(t => conventions.IsMessageType(t)) }, CultureInfo.InvariantCulture); settings.Set(registry); settings.Set(AzureStorageQueueTransport.SerializerSettingsKey, Tuple.Create <SerializationDefinition, SettingsHolder>(new XmlSerializer(), settings)); Assert.DoesNotThrow(() => { var messageMapper = MessageWrapperSerializer.GetMapper(); AzureStorageQueueTransport.GetMainSerializerHack(messageMapper, settings); }); }
internal SqlServerTransportInfrastructure(QueueAddressTranslator addressTranslator, SettingsHolder settings, string connectionString) { this.addressTranslator = addressTranslator; this.settings = settings; this.connectionString = connectionString; schemaAndCatalogSettings = settings.GetOrCreate <EndpointSchemaAndCatalogSettings>(); delayedDeliverySettings = settings.GetOrDefault <DelayedDeliverySettings>(); var timeoutManagerFeatureDisabled = settings.GetOrDefault <FeatureState>(typeof(TimeoutManager).FullName) == FeatureState.Disabled; diagnostics.Add("NServiceBus.Transport.SqlServer.TimeoutManager", new { FeatureEnabled = !timeoutManagerFeatureDisabled }); if (delayedDeliverySettings != null && timeoutManagerFeatureDisabled) { delayedDeliverySettings.DisableTimeoutManagerCompatibility(); } }
public override TransportInfrastructure Initialize(SettingsHolder settings, string connectionString) { // configure JSON instead of XML as the default serializer: SetMainSerializer(settings, new JsonSerializer()); // register the MessageWrapper as a system message to have it registered in mappings and serializers settings.GetOrCreate <Conventions>().AddSystemMessagesConventions(t => t == typeof(MessageWrapper)); settings.Set("Recoverability.DisableLegacyRetriesSatellite", true); var appSettings = ConfigurationManager.AppSettings; settings.Set(WellKnownConfigurationKeys.KafkaDebugEnabled, Convert.ToBoolean(appSettings[WellKnownConfigurationKeys.KafkaDebugEnabled] ?? "false")); settings.Set(WellKnownConfigurationKeys.KafkaSessionTimeout, Convert.ToInt32(appSettings[WellKnownConfigurationKeys.KafkaSessionTimeout] ?? "30000")); settings.Set(WellKnownConfigurationKeys.KafkaHeartBeatInterval, Convert.ToInt32(appSettings[WellKnownConfigurationKeys.KafkaHeartBeatInterval] ?? "5000")); settings.Set(WellKnownConfigurationKeys.CreateQueues, Convert.ToBoolean(appSettings[WellKnownConfigurationKeys.CreateQueues] ?? "false")); settings.Set(WellKnownConfigurationKeys.KafkaPathToBin, appSettings[WellKnownConfigurationKeys.KafkaPathToBin] ?? @"C:\kafka_2.11-0.10.1.0\bin\windows"); settings.Set(WellKnownConfigurationKeys.KafkaZooKeeperUrl, appSettings[WellKnownConfigurationKeys.KafkaZooKeeperUrl] ?? @"localhost:2181"); settings.Set(WellKnownConfigurationKeys.NumberOfPartitions, appSettings[WellKnownConfigurationKeys.NumberOfPartitions] ?? @"1"); settings.Set(WellKnownConfigurationKeys.ReplicationFactor, appSettings[WellKnownConfigurationKeys.ReplicationFactor] ?? @"1"); // TODO: register metadata of the wrapper for the sake of XML serializer MessageMetadataRegistry registry; if (settings.TryGet(out registry) == false) { const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance; registry = (MessageMetadataRegistry)Activator.CreateInstance(typeof(MessageMetadataRegistry), flags, null, new object[] { settings.GetOrCreate <Conventions>() }, CultureInfo.InvariantCulture); settings.Set <MessageMetadataRegistry>(registry); } settings.Get <MessageMetadataRegistry>().GetMessageMetadata(typeof(MessageWrapper)); settings.SetDefault(WellKnownConfigurationKeys.ConnectionString, connectionString); return(new KafkaTransportInfrastructure(settings, connectionString)); }
internal AzureServiceBusSubscriptionSettings(SettingsHolder settings) : base(settings) { subscriptionSettings = settings.GetOrCreate <TopologySettings>().SubscriptionSettings; }
public LegacySqlServerTransportInfrastructure(LegacyQueueAddressTranslator addressTranslator, SettingsHolder settings) { this.addressTranslator = addressTranslator; this.settings = settings; this.schemaAndCatalogSettings = settings.GetOrCreate <EndpointSchemaAndCatalogSettings>(); }
internal AzureServiceBusTopicSettings(SettingsHolder settings) : base(settings) { topicSettings = settings.GetOrCreate <TopologySettings>().TopicSettings; }
/// <inheritdoc cref="Initialize"/> public override async Task <TransportInfrastructure> Initialize(HostSettings hostSettings, ReceiveSettings[] receiversSettings, string[] sendingAddresses, CancellationToken cancellationToken = default) { if (queueServiceClientProvider == null) { //legacy shim API guard: if queueServiceClientProvider is null it means that ConnectionString() has not been invoked throw new Exception("Cannot initialize the transport without a valid connection " + "string or a configured QueueServiceClient. If using the obsoleted API to " + "configure the transport, make sure to call transportConfig.ConnectionString() " + "to configure the client connection string."); } Guard.AgainstNull(nameof(hostSettings), hostSettings); Guard.AgainstNull(nameof(receiversSettings), receiversSettings); Guard.AgainstNull(nameof(sendingAddresses), sendingAddresses); ValidateReceiversSettings(receiversSettings); if (hostSettings.SetupInfrastructure) { var queuesToCreate = receiversSettings.Select(settings => settings.ReceiveAddress).Union(sendingAddresses).ToList(); if (SupportsDelayedDelivery && !string.IsNullOrWhiteSpace(DelayedDelivery.DelayedDeliveryPoisonQueue)) { queuesToCreate.Add(DelayedDelivery.DelayedDeliveryPoisonQueue); } var queueCreator = new AzureMessageQueueCreator(queueServiceClientProvider, GetQueueAddressGenerator()); await queueCreator.CreateQueueIfNecessary(queuesToCreate, cancellationToken) .ConfigureAwait(false); } var localAccountInfo = new AccountInfo("", queueServiceClientProvider.Client, cloudTableClientProvider.Client); var azureStorageAddressing = new AzureStorageAddressingSettings(GetQueueAddressGenerator(), AccountRouting.DefaultAccountAlias, Subscriptions.SubscriptionTableName, AccountRouting.Mappings, localAccountInfo); object delayedDeliveryPersistenceDiagnosticSection = new { }; CloudTable delayedMessagesStorageTable = null; var nativeDelayedDeliveryPersistence = NativeDelayDeliveryPersistence.Disabled(); if (SupportsDelayedDelivery) { delayedMessagesStorageTable = await EnsureNativeDelayedDeliveryTable( hostSettings.Name, DelayedDelivery.DelayedDeliveryTableName, cloudTableClientProvider.Client, hostSettings.SetupInfrastructure, cancellationToken).ConfigureAwait(false); nativeDelayedDeliveryPersistence = new NativeDelayDeliveryPersistence(delayedMessagesStorageTable); delayedDeliveryPersistenceDiagnosticSection = new { DelayedDeliveryTableName = delayedMessagesStorageTable.Name, UserDefinedDelayedDeliveryTableName = !string.IsNullOrWhiteSpace(DelayedDelivery.DelayedDeliveryTableName) }; } var serializerSettingsHolder = hostSettings.CoreSettings; if (serializerSettingsHolder == null) { //in raw transport mode to set up the required serializer a settings holder //is needed to store MessageMetadataRegistry and Conventions instances. //https://github.com/Particular/NServiceBus.AzureStorageQueues/issues/524 var tempSettingsHolder = new SettingsHolder(); const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance; var conventions = tempSettingsHolder.GetOrCreate <Conventions>(); var registry = (MessageMetadataRegistry)Activator.CreateInstance(typeof(MessageMetadataRegistry), flags, null, new object[] { new Func <Type, bool>(t => conventions.IsMessageType(t)) }, CultureInfo.InvariantCulture); tempSettingsHolder.Set(registry); serializerSettingsHolder = tempSettingsHolder; } var serializer = BuildSerializer(MessageWrapperSerializationDefinition, serializerSettingsHolder); object subscriptionsPersistenceDiagnosticSection = new { }; ISubscriptionStore subscriptionStore = new NoOpSubscriptionStore(); if (SupportsPublishSubscribe) { var subscriptionTable = await EnsureSubscriptionTableExists(cloudTableClientProvider.Client, Subscriptions.SubscriptionTableName, hostSettings.SetupInfrastructure, cancellationToken) .ConfigureAwait(false); object subscriptionPersistenceCachingSection = new { IsEnabled = false }; subscriptionStore = new SubscriptionStore(azureStorageAddressing); if (Subscriptions.DisableCaching == false) { subscriptionPersistenceCachingSection = new { IsEnabled = true, Subscriptions.CacheInvalidationPeriod }; subscriptionStore = new CachedSubscriptionStore(subscriptionStore, Subscriptions.CacheInvalidationPeriod); } subscriptionsPersistenceDiagnosticSection = new { SubscriptionTableName = subscriptionTable.Name, UserDefinedSubscriptionTableName = !string.IsNullOrWhiteSpace(Subscriptions.SubscriptionTableName), Caching = subscriptionPersistenceCachingSection }; } var dispatcher = new Dispatcher(GetQueueAddressGenerator(), azureStorageAddressing, serializer, nativeDelayedDeliveryPersistence, subscriptionStore); object delayedDeliveryProcessorDiagnosticSection = new { }; var nativeDelayedDeliveryProcessor = NativeDelayedDeliveryProcessor.Disabled(); if (SupportsDelayedDelivery) { var nativeDelayedDeliveryErrorQueue = DelayedDelivery.DelayedDeliveryPoisonQueue ?? hostSettings.CoreSettings?.GetOrDefault <string>(ErrorQueueSettings.SettingsKey) ?? receiversSettings.Select(settings => settings.ErrorQueue).FirstOrDefault(); nativeDelayedDeliveryProcessor = new NativeDelayedDeliveryProcessor( dispatcher, delayedMessagesStorageTable, blobServiceClientProvider.Client, nativeDelayedDeliveryErrorQueue, TransportTransactionMode, new BackoffStrategy(PeekInterval, MaximumWaitTimeWhenIdle)); nativeDelayedDeliveryProcessor.Start(cancellationToken); delayedDeliveryProcessorDiagnosticSection = new { DelayedDeliveryPoisonQueue = nativeDelayedDeliveryErrorQueue, UserDefinedDelayedDeliveryPoisonQueue = !string.IsNullOrWhiteSpace(DelayedDelivery.DelayedDeliveryPoisonQueue) }; } var messageReceivers = receiversSettings.Select(settings => BuildReceiver(hostSettings, settings, serializer, hostSettings.CriticalErrorAction, subscriptionStore)) .ToDictionary(receiver => receiver.Id, receiver => receiver.Receiver); var infrastructure = new AzureStorageQueueInfrastructure( dispatcher, new ReadOnlyDictionary <string, IMessageReceiver>(messageReceivers), nativeDelayedDeliveryProcessor); hostSettings.StartupDiagnostic.Add("NServiceBus.Transport.AzureStorageQueues", new { ConnectionMechanism = new { Queue = queueServiceClientProvider is QueueServiceClientByConnectionString ? "ConnectionString" : "QueueServiceClient", Table = cloudTableClientProvider is CloudTableClientByConnectionString ? "ConnectionString" : "CloudTableClient", Blob = blobServiceClientProvider is BlobServiceClientProvidedByConnectionString ? "ConnectionString" : "BlobServiceClient", }, MessageWrapperSerializer = MessageWrapperSerializationDefinition == null ? "Default" : "Custom", MessageEnvelopeUnwrapper = MessageUnwrapper == null ? "Default" : "Custom", NativeDelayedDelivery = new { IsEnabled = SupportsDelayedDelivery, Processor = delayedDeliveryProcessorDiagnosticSection, Persistence = delayedDeliveryPersistenceDiagnosticSection }, Subscriptions = new { IsEnabled = SupportsPublishSubscribe, Persistence = subscriptionsPersistenceDiagnosticSection }, TransactionMode = Enum.GetName(typeof(TransportTransactionMode), TransportTransactionMode), ReceiverBatchSize = ReceiverBatchSize.HasValue ? ReceiverBatchSize.Value.ToString(CultureInfo.InvariantCulture) : "Default", DegreeOfReceiveParallelism = DegreeOfReceiveParallelism.HasValue ? DegreeOfReceiveParallelism.Value.ToString(CultureInfo.InvariantCulture) : "Default", MaximumWaitTimeWhenIdle, PeekInterval, MessageInvisibleTime }); return(infrastructure); }
public override TransportInfrastructure Initialize(SettingsHolder settings, string connectionString) { settings.GetOrCreate<StartUpSequence>().Add($"{nameof(TransportDefinition)}.{nameof(Initialize)}"); return new FakeTransportInfrastructure(settings); }
internal AzureServiceBusQueueSettings(SettingsHolder settings) : base(settings) { queueSettings = settings.GetOrCreate <TopologySettings>().QueueSettings; }