/// <summary> /// Called when the features is activated /// </summary> protected override void Setup(FeatureConfigurationContext context) { var endpointName = context.Settings.EndpointName(); var applicativeInputQueue = Address.Parse(endpointName).SubScope("worker"); context.Container.ConfigureComponent<UnicastBus>(DependencyLifecycle.SingleInstance) .ConfigureProperty(r => r.InputAddress, applicativeInputQueue) .ConfigureProperty(r => r.DoNotStartTransport, !context.Settings.GetOrDefault<bool>("Distributor.WithWorker")); if (!context.Container.HasComponent<WorkerQueueCreator>()) { context.Container.ConfigureComponent<WorkerQueueCreator>(DependencyLifecycle.InstancePerCall) .ConfigureProperty(p => p.DistributorEnabled, true) .ConfigureProperty(p => p.Address, applicativeInputQueue); } else { context.Container.ConfigureProperty<WorkerQueueCreator>(p => p.DistributorEnabled, true); context.Container.ConfigureProperty<WorkerQueueCreator>(p => p.Address, applicativeInputQueue); } if (!context.Container.HasComponent<IWorkerAvailabilityManager>()) { context.Container.ConfigureComponent<MsmqWorkerAvailabilityManager>(DependencyLifecycle.SingleInstance); } Logger.InfoFormat("Endpoint configured to host the distributor, applicative input queue re routed to {0}", applicativeInputQueue); }
/// <summary> /// <see cref="Feature.Setup"/> /// </summary> protected internal override void Setup(FeatureConfigurationContext context) { var criticalTimeCounter = PerformanceCounterHelper.InstantiatePerformanceCounter("Critical Time", context.Settings.EndpointName()); var criticalTimeCalculator = new CriticalTimeCalculator(criticalTimeCounter); context.Container.RegisterSingleton(criticalTimeCalculator); context.Pipeline.Register<CriticalTimeBehavior.Registration>(); }
protected override void Setup(FeatureConfigurationContext context) { var configSection = context.Settings.GetConfigSection<AzureServiceBusQueueConfig>() ?? new AzureServiceBusQueueConfig(); new ContainerConfiguration().Configure(context, configSection); context.Container.ConfigureComponent(b => { var config = b.Build<Configure>(); var messagingFactories = b.Build<IManageMessagingFactoriesLifecycle>(); var subscriptionCreator = b.Build<ICreateSubscriptions>(); var queueCreator = b.Build<ICreateQueues>(); var topicCreator = b.Build<ICreateTopics>(); var queueClients = b.Build<IManageQueueClientsLifecycle>(); var subscriptionClients = b.Build<ICreateSubscriptionClients>(); var topicClients = b.Build<IManageTopicClientsLifecycle>(); var queueClientCreator = b.Build<ICreateQueueClients>(); // isn't there a better way to call initialize on object creation? var topology = new QueueAndTopicByEndpointTopology(config, messagingFactories, subscriptionCreator,queueCreator, topicCreator, queueClients, subscriptionClients, topicClients, queueClientCreator); topology.Initialize(context.Settings); return topology; }, DependencyLifecycle.SingleInstance); }
protected internal sealed override void Setup(FeatureConfigurationContext context) { var mapper = new MessageMapper(); var settings = context.Settings; var messageMetadataRegistry = settings.Get<MessageMetadataRegistry>(); mapper.Initialize(messageMetadataRegistry.GetAllMessages().Select(m => m.MessageType)); var defaultSerializerAndDefinition = settings.GetMainSerializer(); var defaultSerializer = CreateMessageSerializer(defaultSerializerAndDefinition, mapper, settings); var additionalDeserializers = new List<IMessageSerializer>(); foreach (var definitionAndSettings in context.Settings.GetAdditionalSerializers()) { additionalDeserializers.Add(CreateMessageSerializer(definitionAndSettings, mapper, settings)); } var resolver = new MessageDeserializerResolver(defaultSerializer, additionalDeserializers); var logicalMessageFactory = new LogicalMessageFactory(messageMetadataRegistry, mapper); context.Pipeline.Register(new DeserializeLogicalMessagesConnector(resolver, logicalMessageFactory, messageMetadataRegistry), "Deserializes the physical message body into logical messages"); context.Pipeline.Register(new SerializeMessageConnector(defaultSerializer, messageMetadataRegistry), "Converts a logical message into a physical message"); context.Container.ConfigureComponent(_ => mapper, DependencyLifecycle.SingleInstance); context.Container.ConfigureComponent(_ => messageMetadataRegistry, DependencyLifecycle.SingleInstance); context.Container.ConfigureComponent(_ => logicalMessageFactory, DependencyLifecycle.SingleInstance); LogFoundMessages(messageMetadataRegistry.GetAllMessages().ToList()); }
protected override void Setup(FeatureConfigurationContext context) { var connFactory = PostgreSQLStorageSession.GetConnectionFactory(context.Settings); TimeoutPersister.Initialize(connFactory); context.Container.ConfigureComponent<TimeoutPersister>(DependencyLifecycle.InstancePerCall) .ConfigureProperty(p => p.EndpointName, context.Settings.EndpointName()); }
/// <summary> /// Invoked if the feature is activated. /// </summary> /// <param name="context">The feature context.</param> protected internal override void Setup(FeatureConfigurationContext context) { context.Settings.Get<Conventions>().AddSystemMessagesConventions(t => typeof(ScheduledTask).IsAssignableFrom(t)); var defaultScheduler = new DefaultScheduler(); context.Container.RegisterSingleton(defaultScheduler); context.Pipeline.Register("ScheduleBehavior", new ScheduleBehavior(defaultScheduler), "Registers a task definition for scheduling."); }
/// <summary> /// See <see cref="Feature.Setup"/> /// </summary> protected override void Setup(FeatureConfigurationContext context) { var connectionstring = context.Settings.Get<string>("AzureSagaStorage.ConnectionString"); var updateSchema = context.Settings.Get<bool>("AzureSagaStorage.CreateSchema"); var account = CloudStorageAccount.Parse(connectionstring); context.Container.ConfigureComponent(() => new AzureSagaPersister(account, updateSchema), DependencyLifecycle.InstancePerCall); }
protected override void Setup(FeatureConfigurationContext context) { _connectionFactory = PostgreSQLStorageSession.GetConnectionFactory(context.Settings); OutboxPersister.Initialize(_connectionFactory); context.Container.ConfigureComponent<OutboxPersister>(DependencyLifecycle.InstancePerCall); var frequencyToRunDeduplicationDataCleanup = ReadTimeSpanConfig("NServiceBus/Outbox/PostgreSQL/FrequencyToRunDeduplicationDataCleanup", TimeSpan.FromMinutes(1)); _timeToKeepDeduplicationData = ReadTimeSpanConfig("NServiceBus/Outbox/PostgreSQL/TimeToKeepDeduplicationData", TimeSpan.FromDays(7)); _cleanupTimer = new Timer(PerformCleanup, null, TimeSpan.FromMinutes(1), frequencyToRunDeduplicationDataCleanup); }
protected internal override void Setup(FeatureConfigurationContext context) { var serviceConstructor = context.Settings.GetEncryptionServiceConstructor(); var service = serviceConstructor(); var inspector = new EncryptionInspector(context.Settings.Get<Conventions>()); context.Pipeline.Register(new EncryptBehavior.EncryptRegistration(inspector, service)); context.Pipeline.Register(new DecryptBehavior.DecryptRegistration(inspector, service)); }
protected internal override void Setup(FeatureConfigurationContext context) { var distributorControlAddress = context.Settings.Get<string>("LegacyDistributor.ControlAddress"); var capacity = context.Settings.Get<int>("LegacyDistributor.Capacity"); context.Container.ConfigureComponent(b => new ReadyMessageSender(b.Build<IDispatchMessages>(), context.Settings.LocalAddress(), capacity, distributorControlAddress), DependencyLifecycle.SingleInstance); context.Container.ConfigureComponent(b => new ProcessedMessageCounterBehavior(b.Build<ReadyMessageSender>(), context.Settings.Get<NotificationSubscriptions>()), DependencyLifecycle.SingleInstance); context.RegisterStartupTask(b => b.Build<ReadyMessageSender>()); context.Pipeline.Register("ProcessedMessageCounterBehavior", b => b.Build<ProcessedMessageCounterBehavior>(), "Counts messages processed by the worker."); }
protected internal override void Setup(FeatureConfigurationContext context) { var logicalAddress = context.Settings.LogicalAddress(); var performanceDiagnosticsBehavior = new ReceivePerformanceDiagnosticsBehavior(logicalAddress.EndpointInstance.Endpoint); context.Pipeline.Register(performanceDiagnosticsBehavior, "Provides various performance counters for receive statistics"); context.Pipeline.Register("ProcessingStatistics", new ProcessingStatisticsBehavior(), "Collects timing for ProcessingStarted and adds the state to determine ProcessingEnded"); context.Pipeline.Register("AuditProcessingStatistics", new AuditProcessingStatisticsBehavior(), "Add ProcessingStarted and ProcessingEnded headers"); context.RegisterStartupTask(new WarmupCooldownTask(performanceDiagnosticsBehavior)); }
/// <summary> /// See <see cref="Feature.Setup"/> /// </summary> protected override void Setup(FeatureConfigurationContext context) { //TODO: get rid of these statics SubscriptionServiceContext.SubscriptionTableName = context.Settings.Get<string>("AzureSubscriptionStorage.TableName"); SubscriptionServiceContext.CreateIfNotExist = context.Settings.Get<bool>("AzureSubscriptionStorage.CreateSchema"); var account = CloudStorageAccount.Parse(context.Settings.Get<string>("AzureSubscriptionStorage.ConnectionString")); SubscriptionServiceContext.Init(account.CreateCloudTableClient()); context.Container.ConfigureComponent(() => new AzureSubscriptionStorage(account), DependencyLifecycle.InstancePerCall); }
/// <summary> /// See <see cref="Feature.Setup"/> /// </summary> protected override void Setup(FeatureConfigurationContext context) { //TODO: get rid of these statics ServiceContext.CreateSchema = context.Settings.Get<bool>("AzureTimeoutStorage.CreateSchema"); ServiceContext.TimeoutDataTableName = context.Settings.Get<string>("AzureTimeoutStorage.TimeoutDataTableName"); ServiceContext.TimeoutManagerDataTableName = context.Settings.Get<string>("AzureTimeoutStorage.TimeoutManagerDataTableName"); context.Container.ConfigureComponent<TimeoutPersister>(DependencyLifecycle.InstancePerCall) .ConfigureProperty(tp => tp.ConnectionString, context.Settings.Get<string>("AzureTimeoutStorage.ConnectionString")) .ConfigureProperty(tp => tp.CatchUpInterval, context.Settings.Get<int>("AzureTimeoutStorage.CatchUpInterval")) .ConfigureProperty(tp => tp.PartitionKeyScope, context.Settings.Get<string>("AzureTimeoutStorage.PartitionKeyScope")); }
protected internal override void Setup(FeatureConfigurationContext context) { var transport = context.Settings.Get<OutboundTransport>(); var lazySendingConfigResult = new Lazy<TransportSendInfrastructure>(() => transport.Configure(context.Settings), LazyThreadSafetyMode.ExecutionAndPublication); context.Container.ConfigureComponent(c => { var dispatcher = lazySendingConfigResult.Value.DispatcherFactory(); return dispatcher; }, DependencyLifecycle.SingleInstance); context.RegisterStartupTask(new PrepareForSending(lazySendingConfigResult)); }
/// <summary> /// <see cref="Feature.Setup"/> /// </summary> protected internal override void Setup(FeatureConfigurationContext context) { var connectionString = context.Settings.Get<TransportConnectionString>().GetConnectionStringOrNull(); var selectedTransportDefinition = context.Settings.Get<TransportDefinition>(); if (connectionString == null && RequiresConnectionString) { throw new InvalidOperationException(String.Format(Message, GetConfigFileIfExists(), selectedTransportDefinition.GetType().Name, ExampleConnectionStringForErrorMessage)); } context.Container.RegisterSingleton(selectedTransportDefinition); Configure(context, connectionString); }
public void Should_construct_serializer_that_uses_requested_encoding() { var builder = new BusConfiguration(); builder.TypesToScan(new Type[0]); builder.UseSerialization<JsonSerializer>().Encoding(Encoding.UTF7); var config = builder.BuildConfiguration(); var context = new FeatureConfigurationContext(config); new JsonSerialization().SetupFeature(context); var serializer = config.Builder.Build<JsonMessageSerializer>(); Assert.AreSame(Encoding.UTF7, serializer.Encoding); }
/// <summary> /// See <see cref="Feature.Setup"/> /// </summary> protected override void Setup(FeatureConfigurationContext context) { var cloudBlobClient = CloudStorageAccount.Parse(context.Settings.Get<string>("AzureDataBus.ConnectionString")).CreateCloudBlobClient(); var dataBus = new BlobStorageDataBus(cloudBlobClient.GetContainerReference(context.Settings.Get<string>("AzureDataBus.Container"))) { BasePath = context.Settings.Get<string>("AzureDataBus.BasePath"), MaxRetries = context.Settings.Get<int>("AzureDataBus.MaxRetries"), BackOffInterval = context.Settings.Get<int>("AzureDataBus.BackOffInterval"), NumberOfIOThreads = context.Settings.Get<int>("AzureDataBus.NumberOfIOThreads"), BlockSize = context.Settings.Get<int>("AzureDataBus.BlockSize"), DefaultTTL = context.Settings.Get<long>("AzureDataBus.DefaultTTL") }; context.Container.RegisterSingleton<IDataBus>(dataBus); }
protected override void Setup(FeatureConfigurationContext context) { var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("MySatellite"); var satelliteAddress = context.Settings.GetTransportAddress(satelliteLogicalAddress); context.AddSatelliteReceiver("Test satellite", satelliteAddress, PushRuntimeSettings.Default, (c, ec) => RecoverabilityAction.MoveToError(c.Failed.ErrorQueue), (builder, pushContext) => { var testContext = builder.Build<Context>(); testContext.MessageReceived = true; testContext.TransportTransactionAddedToContext = ReferenceEquals(pushContext.Context.Get<TransportTransaction>(), pushContext.TransportTransaction); return Task.FromResult(true); }); Address = satelliteAddress; }
protected override void Setup(FeatureConfigurationContext context) { var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("MySatellite"); var satelliteAddress = context.Settings.GetTransportAddress(satelliteLogicalAddress); #pragma warning disable 612, 618 context.AddSatelliteReceiver("Test satellite", satelliteAddress, TransportTransactionMode.None, PushRuntimeSettings.Default, (c, ec) => RecoverabilityAction.MoveToError(c.Failed.ErrorQueue), (builder, pushContext) => { var testContext = builder.Build<Context>(); testContext.MessageReceived = true; return Task.FromResult(true); }); #pragma warning restore 612, 618 Address = satelliteAddress; }
/// <summary> /// <see cref="Feature.Setup" />. /// </summary> protected internal override void Setup(FeatureConfigurationContext context) { var inboundTransport = context.Settings.Get<InboundTransport>(); context.Settings.Get<QueueBindings>().BindReceiving(context.Settings.LocalAddress()); var instanceSpecificQueue = context.Settings.InstanceSpecificQueue(); if (instanceSpecificQueue != null) { context.Settings.Get<QueueBindings>().BindReceiving(instanceSpecificQueue); } var lazyReceiveConfigResult = new Lazy<TransportReceiveInfrastructure>(() => inboundTransport.Configure(context.Settings)); context.Container.ConfigureComponent(b => lazyReceiveConfigResult.Value.MessagePumpFactory(), DependencyLifecycle.InstancePerCall); context.Container.ConfigureComponent(b => lazyReceiveConfigResult.Value.QueueCreatorFactory(), DependencyLifecycle.SingleInstance); context.RegisterStartupTask(new PrepareForReceiving(lazyReceiveConfigResult)); }
protected internal override void Setup(FeatureConfigurationContext context) { var unicastBusConfig = context.Settings.GetConfigSection<UnicastBusConfig>(); if (!string.IsNullOrWhiteSpace(unicastBusConfig?.ForwardReceivedMessagesTo)) { throw new NotSupportedException($"The {nameof(UnicastBusConfig.ForwardReceivedMessagesTo)} attribute in the {nameof(UnicastBusConfig)} configuration section is no longer supported. Switch to the code API by using `{nameof(EndpointConfiguration)}.ForwardReceivedMessagesTo` instead."); } if (!string.IsNullOrWhiteSpace(unicastBusConfig?.DistributorControlAddress)) { throw new NotSupportedException($"The {nameof(UnicastBusConfig.DistributorControlAddress)} attribute in the {nameof(UnicastBusConfig)} configuration section is no longer supported. Remove this from the configuration section. Switch to the code API by using `{nameof(EndpointConfiguration)}.EnlistWithLegacyMSMQDistributor` instead."); } if (!string.IsNullOrWhiteSpace(unicastBusConfig?.DistributorDataAddress)) { throw new NotSupportedException($"The {nameof(UnicastBusConfig.DistributorDataAddress)} attribute in the {nameof(UnicastBusConfig)} configuration section is no longer supported. Remove this from the configuration section. Switch to the code API by using `{nameof(EndpointConfiguration)}.EnlistWithLegacyMSMQDistributor` instead."); } var masterNodeConfig = context.Settings.GetConfigSection<MasterNodeConfig>(); if (masterNodeConfig != null) { throw new NotSupportedException($"The {nameof(MasterNodeConfig)} configuration section is no longer supported. Remove this from this configuration section. Switch to the code API by using `{nameof(EndpointConfiguration)}.EnlistWithLegacyMSMQDistributor` instead."); } var secondLevelRetriesConfig = context.Settings.GetConfigSection<SecondLevelRetriesConfig>(); if (secondLevelRetriesConfig != null) { throw new NotSupportedException($"The {nameof(SecondLevelRetriesConfig)} configuration section is no longer supported. Remove this from this configuration section. Switch to the code API by using `endpointConfiguration.Recoverability().Delayed(settings => ...)` instead."); } var transportConfig = context.Settings.GetConfigSection<TransportConfig>(); if (transportConfig != null) { throw new NotSupportedException($"The {nameof(TransportConfig)} configuration section is no longer supported. Remove this from this configuration section. Switch to the code API by using `endpointConfiguration.LimitMessageProcessingConcurrencyTo(1)` to change the concurrency level or `endpointConfiguration.Recoverability().Immediate(settings => settings.NumberOfRetries(5)` to change the number of immediate retries instead."); } }
/// <summary> /// Called when the features is activated /// </summary> protected override void Setup(FeatureConfigurationContext context) { if (!context.Settings.GetOrDefault<bool>("Distributor.Enabled")) { var workerName = ConfigurationManager.AppSettings.Get("NServiceBus/Distributor/WorkerNameToUseWhileTesting"); if (String.IsNullOrEmpty(workerName)) { ValidateMasterNodeAddress(context.Settings); } } var masterNodeAddress = MasterNodeConfiguration.GetMasterNodeAddress(context.Settings); var distributorControlAddress = masterNodeAddress.SubScope("distributor.control"); var unicastBusConfig = context.Settings.GetConfigSection<UnicastBusConfig>(); //allow users to override control address in config if (unicastBusConfig != null && !string.IsNullOrWhiteSpace(unicastBusConfig.DistributorControlAddress)) { distributorControlAddress = Address.Parse(unicastBusConfig.DistributorControlAddress); } if (!context.Container.HasComponent<WorkerQueueCreator>()) { context.Container.ConfigureComponent<WorkerQueueCreator>(DependencyLifecycle.InstancePerCall) .ConfigureProperty(p => p.WorkerEnabled, true); } else { context.Container.ConfigureProperty<WorkerQueueCreator>(p => p.WorkerEnabled, true); } context.Container.ConfigureComponent<ReadyMessageSender>(DependencyLifecycle.SingleInstance) .ConfigureProperty(p => p.DistributorControlAddress, distributorControlAddress); }
protected override void Setup(FeatureConfigurationContext context) { context.RegisterStartupTask(b => new SendMessageWhileStartingTask()); }
protected override void Setup(FeatureConfigurationContext context) { context.Services.AddSingleton <Dependency>(); context.Services.AddSingleton <Runner>(); context.RegisterStartupTask(b => b.GetService <Runner>()); }
protected internal override void Setup(FeatureConfigurationContext context) { context.Pipeline.Register("AttachCorrelationId", new AttachCorrelationIdBehavior(), "Makes sure that outgoing messages have a correlation id header set"); }
protected override void Setup(FeatureConfigurationContext context) { throw new System.NotImplementedException(); }
protected override void Setup(FeatureConfigurationContext context) { context.Container.ConfigureComponent <StaleIndexChecker>(DependencyLifecycle.SingleInstance); context.Container.ConfigureComponent <StaleIndexInfoStore>(DependencyLifecycle.SingleInstance); }
protected override void Setup(FeatureConfigurationContext context) { context.RegisterStartupTask(b => new DelayReceiverFromStartingTask()); }
protected override void Setup(FeatureConfigurationContext context) { }
protected override void Setup(FeatureConfigurationContext context) { context.Container.RegisterSingleton(new ConnectionFactoryHolder{ConnectionFactory = CreateConnectionFactory()}); }
protected override void Setup(FeatureConfigurationContext context) { context.RegisterStartupTask(b => new SetupScheduledActionTask(b.Build<Context>())); }
protected override void Setup(FeatureConfigurationContext context) { context.RegisterStartupTask(b => new AfterConfigIsCompleteFeatureTask(b.Build<ReadOnlySettings>(), b.Build<Context>())); }
protected override void Setup(FeatureConfigurationContext context) { var testContext = (Context) context.Settings.Get<ScenarioContext>(); testContext.TypedDependencyFeatureSetUp = true; }
protected override void Setup(FeatureConfigurationContext context) { var testContext = context.Settings.Get<TimeoutTestContext>(); context.Container.ConfigureComponent(b => new CyclingOutageTimeoutPersister(testContext.SecondsToWait), DependencyLifecycle.SingleInstance); }
/// <summary> /// Allows serialization features to verify their <see cref="Feature"/> Prerequisites /// </summary> public static bool ShouldSerializationFeatureBeEnabled(this Feature serializationFeature, FeatureConfigurationContext context) { var serializationDefinition = context.Settings.GetSelectedSerializer(); return serializationDefinition.ProvidedByFeature() == serializationFeature.GetType(); }