public void Should_not_register_defaults_if_feature_is_not_activated() { var settings = new SettingsHolder(); var featureSettings = new FeatureActivator(settings); featureSettings.Add(new MyFeatureWithDefaultsNotActive()); featureSettings.Add(new MyFeatureWithDefaultsNotActiveDueToUnsatisfiedPrerequisite()); featureSettings.SetupFeatures(new FeatureConfigurationContext(null)); Assert.False(settings.HasSetting("Test1")); Assert.False(settings.HasSetting("Test2")); }
/// <summary> /// Enables the given infrastructure service by registering it in the container /// </summary> /// <typeparam name="T"></typeparam> public static void Enable <T>() { var serviceType = typeof(T); if (Configure.Instance.Configurer.HasComponent <T>()) { Logger.InfoFormat("Infrastructure service {0} was found in the container and will be used instead of the default", serviceType.FullName); SetStatusToEnabled(serviceType); //todo: We should guide users to register their infrastructure overrides in a more explicit way in the future return; } if (!SettingsHolder.HasSetting <T>()) { throw new ConfigurationErrorsException(string.Format("No explicit settings or default found for service {0}, please configure one explicitly", serviceType.FullName)); } var configAction = SettingsHolder.Get <Action>(serviceType.FullName); configAction(); SetStatusToEnabled(serviceType); Logger.DebugFormat("Infrastructure service {0} has been configured", serviceType.FullName); }
static bool LegacyMultiInstanceModeTurnedOn(SettingsHolder settings) { var legacyMode = settings.TryGet(SettingsKeys.LegacyMultiInstanceConnectionFactory, out Func <string, Task <SqlConnection> > _); if (legacyMode && settings.HasSetting(SettingsKeys.MultiCatalogEnabled)) { throw new Exception("Multi-catalog configuration is not supported in legacy multi instance mode. Please configure each catalog using a separate connection string."); } return(legacyMode); }
public void Should_register_defaults_if_feature_is_activated() { var settings = new SettingsHolder(); var featureSettings = new FeatureActivator(settings); featureSettings.Add(new MyFeatureWithDefaults()); featureSettings.SetupFeatures(new FeatureConfigurationContext(null)); Assert.True(settings.HasSetting("Test1")); }
void RegisterMessageOwnersAndBusAddress(IEnumerable <Type> knownMessages) { var unicastConfig = Configure.GetConfigSection <UnicastBusConfig>(); var router = new StaticMessageRouter(knownMessages); var key = typeof(DefaultAutoSubscriptionStrategy).FullName + ".SubscribePlainMessages"; if (SettingsHolder.HasSetting(key)) { router.SubscribeToPlainMessages = SettingsHolder.Get <bool>(key); } Configure.Instance.Configurer.RegisterSingleton <StaticMessageRouter>(router); if (unicastConfig == null) { return; } if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo)) { var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo); Configure.Instance.Configurer.ConfigureProperty <UnicastBus>(b => b.ForwardReceivedMessagesTo, forwardAddress); Configure.Instance.Configurer.ConfigureProperty <ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress); } Configure.Instance.Configurer.ConfigureProperty <UnicastBus>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); Configure.Instance.Configurer.ConfigureProperty <ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast <MessageEndpointMapping>() .OrderByDescending(m => m) .ToList(); foreach (var mapping in messageEndpointMappings) { mapping.Configure((messageType, address) => { if (!(MessageConventionExtensions.IsMessageType(messageType) || MessageConventionExtensions.IsEventType(messageType) || MessageConventionExtensions.IsCommandType(messageType))) { return; } if (MessageConventionExtensions.IsEventType(messageType)) { router.RegisterEventRoute(messageType, address); return; } router.RegisterMessageRoute(messageType, address); }); } }
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); }
bool UserSuppressedTimeoutPersistenceWarning() { if (settingsHolder.HasSetting(SuppressOutdatedTimeoutPersistenceWarning)) { return(settingsHolder.GetOrDefault <bool>(SuppressOutdatedTimeoutPersistenceWarning)); } var appSetting = ConfigurationManager.AppSettings[SuppressOutdatedTimeoutPersistenceWarning]; if (appSetting != null) { return(bool.Parse(appSetting)); } return(false); }
IPushMessages CreateMessagePump() { MessageConverter messageConverter; if (settings.HasSetting(SettingsKeys.CustomMessageIdStrategy)) { messageConverter = new MessageConverter(settings.Get <Func <BasicDeliverEventArgs, string> >(SettingsKeys.CustomMessageIdStrategy)); } else { messageConverter = new MessageConverter(); } string hostDisplayName; if (!settings.TryGet("NServiceBus.HostInformation.DisplayName", out hostDisplayName)) { hostDisplayName = Support.RuntimeEnvironment.MachineName; } var consumerTag = $"{hostDisplayName} - {settings.EndpointName()}"; var queuePurger = new QueuePurger(connectionFactory); TimeSpan timeToWaitBeforeTriggeringCircuitBreaker; if (!settings.TryGet(SettingsKeys.TimeToWaitBeforeTriggeringCircuitBreaker, out timeToWaitBeforeTriggeringCircuitBreaker)) { timeToWaitBeforeTriggeringCircuitBreaker = TimeSpan.FromMinutes(2); } int prefetchMultiplier; if (!settings.TryGet(SettingsKeys.PrefetchMultiplier, out prefetchMultiplier)) { prefetchMultiplier = 3; } ushort prefetchCount; if (!settings.TryGet(SettingsKeys.PrefetchCount, out prefetchCount)) { prefetchCount = 0; } return(new MessagePump(connectionFactory, messageConverter, consumerTag, channelProvider, queuePurger, timeToWaitBeforeTriggeringCircuitBreaker, prefetchMultiplier, prefetchCount)); }
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); }
static void MatchSettingsToConsistencyRequirements(SettingsHolder settings) { if (settings.HasSetting <TransportTransactionMode>()) { var required = settings.Get <TransportTransactionMode>(); if (required > TransportTransactionMode.SendsAtomicWithReceive) { throw new InvalidOperationException($"Azure Service Bus transport doesn't support the required transaction mode {required}."); } if (required > settings.SupportedTransactionMode()) { throw new InvalidOperationException($"Azure Service Bus transport doesn't support the required transaction mode {required}, for the given configuration settings."); } if (required < settings.SupportedTransactionMode()) { if (required < TransportTransactionMode.SendsAtomicWithReceive) { // turn send via off so that sends are not atomic settings.Set(WellKnownConfigurationKeys.Connectivity.SendViaReceiveQueue, false); } if (required == TransportTransactionMode.None) { // immediately delete after receive settings.Set(WellKnownConfigurationKeys.Connectivity.MessageReceivers.ReceiveMode, ReceiveMode.ReceiveAndDelete); // override the default for prefetch count, but user code can still take precedence settings.SetDefault(WellKnownConfigurationKeys.Connectivity.MessageReceivers.PrefetchCount, 0); if (!settings.HasExplicitValue(WellKnownConfigurationKeys.Connectivity.MessageReceivers.PrefetchCount)) { logger.Warn("Default value for message receiver's PrefetchCount was reduced to zero to avoid message loss with ReceiveAndDelete receive mode. To enforce prefetch, use the configuration API to set the value explicitly."); } } } } }
public override void Initialize() { var retriesConfig = Configure.GetConfigSection <SecondLevelRetriesConfig>(); SetUpRetryPolicy(retriesConfig); var processorAddress = Address.Parse(Configure.EndpointName).SubScope("Retries"); var useRemoteRetryProcessor = SettingsHolder.HasSetting("SecondLevelRetries.AddressOfRetryProcessor"); if (useRemoteRetryProcessor) { processorAddress = SettingsHolder.Get <Address>("SecondLevelRetries.AddressOfRetryProcessor"); } Configure.Instance.Configurer.ConfigureProperty <FaultManager>(fm => fm.RetriesErrorQueue, processorAddress); Configure.Instance.Configurer.ConfigureProperty <SecondLevelRetriesProcessor>(rs => rs.InputAddress, processorAddress); Configure.Instance.Configurer.ConfigureProperty <SecondLevelRetriesProcessor>(rs => rs.RetryPolicy, SettingsHolder.Get <Func <TransportMessage, TimeSpan> >("SecondLevelRetries.RetryPolicy")); if (useRemoteRetryProcessor) { Configure.Instance.Configurer.ConfigureProperty <SecondLevelRetriesProcessor>(rs => rs.Disabled, true); } }
/// <summary> /// Returns true if the requested service is available and can be enabled on demand /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static bool IsAvailable <T>() { return(SettingsHolder.HasSetting <T>()); }