/// <summary> /// Wrap the given configure object storing its builder and configurer. /// </summary> /// <param name="config"></param> public void Configure(Configure config) { Builder = config.Builder; Configurer = config.Configurer; busConfig = Configurer.ConfigureComponent <TpUnicastBus>(ComponentCallModelEnum.Singleton); ConfigureSubscriptionAuthorization(); RegisterMessageModules(); var cfg = GetConfigSection <UnicastBusConfig>(); if (cfg != null) { TypesToScan.Where(t => typeof(IMessage).IsAssignableFrom(t)).ToList() .ForEach(t => assembliesToEndpoints[t.Assembly.GetName().Name] = string.Empty); foreach (MessageEndpointMapping mapping in cfg.MessageEndpointMappings) { assembliesToEndpoints[mapping.Messages] = mapping.Endpoint; } busConfig.ConfigureProperty(b => b.DistributorControlAddress, cfg.DistributorControlAddress); busConfig.ConfigureProperty(b => b.DistributorDataAddress, cfg.DistributorDataAddress); busConfig.ConfigureProperty(b => b.ForwardReceivedMessagesTo, cfg.ForwardReceivedMessagesTo); busConfig.ConfigureProperty(b => b.MessageOwners, assembliesToEndpoints); } }
/// <summary> /// Scans the given types for types that are message handlers /// then uses the Configurer to configure them into the container as single call components, /// finally passing them to the bus as its MessageHandlerTypes. /// </summary> /// <param name="types"></param> /// <returns></returns> protected ConfigTpUnicastBus ConfigureMessageHandlersIn(IEnumerable <Type> types) { var handlers = new List <Type>(); var sagaHandlers = new List <Type>(); foreach (Type t in types) { if (IsMessageHandler(t)) { Configurer.ConfigureComponent(t, ComponentCallModelEnum.Singlecall); handlers.Add(t); } } foreach (Type t in types) { if (IsSagaMessageHandler(t)) { sagaHandlers.Add(t); } } busConfig.ConfigureProperty(b => b.MessageHandlerTypes, handlers); busConfig.ConfigureProperty(b => b.SagaMessageHandlerTypes, sagaHandlers); return(this); }
void ConfigureMessageRegistry(List <Type> knownMessages) { var messageRegistry = new MessageMetadataRegistry { DefaultToNonPersistentMessages = !SettingsHolder.Get <bool>("Endpoint.DurableMessages") }; knownMessages.ForEach(messageRegistry.RegisterMessageType); Configurer.RegisterSingleton <MessageMetadataRegistry>(messageRegistry); if (!Logger.IsInfoEnabled) { return; } var messageDefinitions = messageRegistry.GetAllMessages().ToList(); Logger.InfoFormat("Number of messages found: {0}", messageDefinitions.Count()); if (!Logger.IsDebugEnabled) { return; } Logger.DebugFormat("Message definitions: \n {0}", string.Concat(messageDefinitions.Select(md => md.ToString() + "\n"))); }
public static Configurer WithArkDefaultTargetsAndRules(this Configurer @this, string logTableName, string connectionString, string mailFrom, string mailTo, string smtpConnectionString, bool consoleEnabled = false, bool async = true) { if (consoleEnabled) { @this .WithConsoleTarget(async) .WithConsoleRule("*", LogLevel.Trace); } if (!string.IsNullOrWhiteSpace(connectionString)) { @this .WithDatabaseTarget(logTableName, connectionString, async) .WithDatabaseRule("*", LogLevel.Info); } if (!string.IsNullOrWhiteSpace(smtpConnectionString)) { @this .WithMailTarget(mailFrom, mailTo, smtpConnectionString, async: false) .WithMailRule("*", LogLevel.Fatal) ; } if (Debugger.IsAttached) { @this .WithDebuggerTarget() .WithDebuggerRule() ; } return(@this); }
public static Configurer WithDefaultRules(this Configurer @this) { return(@this.WithConsoleRule("*", LogLevel.Trace) .WithDatabaseRule("*", LogLevel.Info) .WithMailRule("*", LogLevel.Fatal) ); }
public static Configurer WithDefaultTargets(this Configurer @this, string logTableName, string connectionString, string mailFrom, string mailTo, bool async = true) { return(@this.WithConsoleTarget(async) .WithDatabaseTarget(logTableName, connectionString, async) .WithMailTarget(mailFrom, mailTo, async: false) ); }
public FrameworkStartup(IConfigureSplits configureSplits, EventOrdering eventOrdering, IViewRenderer renderer) { _configureSplits = configureSplits; _renderer = renderer; _eventOrdering = eventOrdering; _configurer = new Configurer(_eventOrdering); }
protected async Task StartPump(Func <MessageContext, Task> onMessage, Func <ErrorContext, Task <ErrorHandleResult> > onError, TransportTransactionMode transactionMode, Action <string, Exception> onCriticalError = null) { InputQueueName = GetTestName() + transactionMode; ErrorQueueName = $"{InputQueueName}.error"; transportSettings.Set("NServiceBus.Routing.EndpointName", InputQueueName); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(InputQueueName); queueBindings.BindSending(ErrorQueueName); transportSettings.Set(ErrorQueueSettings.SettingsKey, ErrorQueueName); transportSettings.Set <QueueBindings>(queueBindings); transportSettings.Set <EndpointInstances>(new EndpointInstances()); Configurer = CreateConfigurer(); var configuration = Configurer.Configure(transportSettings, transactionMode); TransportInfrastructure = configuration.TransportInfrastructure; IgnoreUnsupportedTransactionModes(transactionMode); IgnoreUnsupportedDeliveryConstraints(); ReceiveInfrastructure = TransportInfrastructure.ConfigureReceiveInfrastructure(); SendInfrastructure = TransportInfrastructure.ConfigureSendInfrastructure(); lazyDispatcher = new Lazy <IDispatchMessages>(() => SendInfrastructure.DispatcherFactory()); MessagePump = ReceiveInfrastructure.MessagePumpFactory(); var queueCreator = ReceiveInfrastructure.QueueCreatorFactory(); await queueCreator.CreateQueueIfNecessary(queueBindings, WindowsIdentity.GetCurrent().Name); var pushSettings = new PushSettings(InputQueueName, ErrorQueueName, configuration.PurgeInputQueueOnStartup, transactionMode); await MessagePump.Init( context => { if (context.Headers.ContainsKey(TestIdHeaderName) && context.Headers[TestIdHeaderName] == testId) { return(onMessage(context)); } return(Task.FromResult(0)); }, context => { if (context.Message.Headers.ContainsKey(TestIdHeaderName) && context.Message.Headers[TestIdHeaderName] == testId) { return(onError(context)); } return(Task.FromResult(ErrorHandleResult.Handled)); }, new FakeCriticalError(onCriticalError), pushSettings); MessagePump.Start(configuration.PushRuntimeSettings); }
public void Configure(Configure config) { Builder = config.Builder; Configurer = config.Configurer; _receiverConfig = Configurer.ConfigureComponent <ServiceBrokerMessageReceiver>(DependencyLifecycle.SingleInstance); _senderConfig = Configurer.ConfigureComponent <ServiceBrokerMessageSender>(DependencyLifecycle.SingleInstance); _failureConfig = Configurer.ConfigureComponent <ServiceBrokerFailureManager>(DependencyLifecycle.SingleInstance); var cfg = GetConfigSection <ServiceBrokerTransportConfig>(); if (cfg == null) { return; } ConnectionString(cfg.ConnectionString); SecondsToWaitForMessage(cfg.SecondsToWaitForMessage); InitiatorService(cfg.InitiatorService); ReceiveBatchSize(cfg.ReceiveBatchSize); EndConversationAfterReceive(cfg.EndConversationAfterReceive); }
public void Deserialize_StoresKeyAndConfig() { // Arrange MissingConfigurationKeyException exception; var config = new Configurer(); try { throw new MissingConfigurationKeyException("Foo", config); } catch (MissingConfigurationKeyException ex) { exception = ex; } var formatter = new BinaryFormatter(); var stream = new MemoryStream(); formatter.Serialize(stream, exception); stream.Seek(0, SeekOrigin.Begin); // Act var resultException = (MissingConfigurationKeyException)formatter.Deserialize(stream); // Assert Assert.That(resultException.Key, Is.EqualTo("Foo")); Assert.That(resultException.Configuration, Is.EqualTo(config.ToString())); }
public void TearDown() { testCancellationTokenSource?.Dispose(); MessagePump?.Stop().GetAwaiter().GetResult(); TransportInfrastructure?.Stop().GetAwaiter().GetResult(); Configurer?.Cleanup().GetAwaiter().GetResult(); }
public void Configure(Configure config) { this.Builder = config.Builder; this.Configurer = config.Configurer; this.config = Configurer.ConfigureComponent <RabbitMqTransport>(ComponentCallModelEnum.Singleton); var cfg = NServiceBus.Configure.GetConfigSection <RabbitMqTransportConfig>(); if (cfg != null) { this.config.ConfigureProperty(t => t.NumberOfWorkerThreads, cfg.NumberOfWorkerThreads); this.config.ConfigureProperty(t => t.MaximumNumberOfRetries, cfg.MaxRetries); this.config.ConfigureProperty(t => t.InputBroker, cfg.InputBroker); this.config.ConfigureProperty(t => t.InputExchange, cfg.InputExchange); this.config.ConfigureProperty(t => t.InputExchangeType, cfg.InputExchangeType); this.config.ConfigureProperty(t => t.InputQueue, cfg.InputQueue); this.config.ConfigureProperty(t => t.InputRoutingKeys, cfg.InputRoutingKeys); this.config.ConfigureProperty(t => t.DoNotCreateInputExchange, cfg.DoNotCreateInputExchange); this.config.ConfigureProperty(t => t.DoNotCreateInputQueue, cfg.DoNotCreateInputQueue); this.config.ConfigureProperty(t => t.ErrorBroker, cfg.ErrorBroker); this.config.ConfigureProperty(t => t.ErrorExchange, cfg.ErrorExchange); this.config.ConfigureProperty(t => t.ErrorExchangeType, cfg.ErrorExchangeType); this.config.ConfigureProperty(t => t.ErrorQueue, cfg.ErrorQueue); this.config.ConfigureProperty(t => t.ErrorRoutingKeys, cfg.ErrorRoutingKeys); this.config.ConfigureProperty(t => t.DoNotCreateErrorExchange, cfg.DoNotCreateErrorExchange); this.config.ConfigureProperty(t => t.DoNotCreateErrorQueue, cfg.DoNotCreateErrorQueue); this.config.ConfigureProperty(t => t.TransactionTimeout, TimeSpan.FromMinutes(cfg.TransactionTimeout)); this.config.ConfigureProperty(t => t.SendAcknowledgement, cfg.SendAcknowledgement); } }
/// <summary> /// Scans the given types for types that are message handlers /// then uses the Configurer to configure them into the container as single call components, /// finally passing them to the bus as its MessageHandlerTypes. /// </summary> /// <param name="types"></param> /// <returns></returns> ConfigUnicastBus ConfigureMessageHandlersIn(IEnumerable <Type> types) { var handlerRegistry = new MessageHandlerRegistry(); var handlers = new List <Type>(); foreach (var t in types.Where(IsMessageHandler)) { Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerUnitOfWork); handlerRegistry.RegisterHandler(t); handlers.Add(t); } Configurer.RegisterSingleton <IMessageHandlerRegistry>(handlerRegistry); var availableDispatcherFactories = TypesToScan .Where( factory => !factory.IsInterface && typeof(IMessageDispatcherFactory).IsAssignableFrom(factory)) .ToList(); var dispatcherMappings = GetDispatcherFactories(handlers, availableDispatcherFactories); //configure the message dispatcher for each handler busConfig.ConfigureProperty(b => b.MessageDispatcherMappings, dispatcherMappings); Configurer.ConfigureProperty <InvokeHandlersBehavior>(b => b.MessageDispatcherMappings, dispatcherMappings); availableDispatcherFactories.ToList().ForEach(factory => Configurer.ConfigureComponent(factory, DependencyLifecycle.InstancePerUnitOfWork)); return(this); }
void RegisterMessageOwnersAndBusAddress(IEnumerable <Type> knownMessages) { var unicastConfig = GetConfigSection <UnicastBusConfig>(); var router = new StaticMessageRouter(knownMessages); Configurer.RegisterSingleton <IRouteMessages>(router); if (unicastConfig == null) { return; } if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo)) { var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo); busConfig.ConfigureProperty(b => b.ForwardReceivedMessagesTo, forwardAddress); } busConfig.ConfigureProperty(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)) { return; } router.RegisterRoute(messageType, address); }); } }
public ConfigUnicastBus SkipDeserialization() { busConfig.ConfigureProperty(b => b.SkipDeserialization, true); Configurer.ConfigureProperty <ExtractLogicalMessagesBehavior>(b => b.SkipDeserialization, true); return(this); }
#pragma warning disable 0618 void RegisterMessageModules() { TypesToScan .Where(t => typeof(IMessageModule).IsAssignableFrom(t) && !t.IsInterface) .ToList() .ForEach(type => Configurer.ConfigureComponent(type, DependencyLifecycle.InstancePerCall)); }
public MessagesBuilder Add <TMessage>(Func <Configurer <TMessage>, Configurer <TMessage> > configure) { var configurer = new Configurer <TMessage>(); configure(configurer); _consumer(bus => bus.MessageCtor(configurer.InitialCapacity, configurer.Aggregator, configurer.Delayed)); return(this); }
public static Configurer WithDefaultTargetsAndRulesFromConfiguration(this Configurer @this, string logTableName, string mailFrom, IConfiguration cfg, bool async = true, bool disableMailInDevelop = true) { @this.WithDefaultTargetsAndRules( logTableName, cfg.GetConnectionString(NLogDefaultConfigKeys.SqlConnStringName), mailFrom, cfg[NLogDefaultConfigKeys.MailNotificationAddresses.Replace('.', ':')], cfg.GetConnectionString(NLogDefaultConfigKeys.SmtpConnStringName), async); return(@this); }
public static Configurer WithDefaultTargetsFromCloudConfiguration(this Configurer @this, string logTableName, string mailFrom, string mailTo, bool async = true) { return(@this.WithConsoleTarget(async) .WithFileTarget(async) .WithDatabaseTargetFromCloudConfiguration(logTableName, async) .WithMailTargetFromCloudConfiguration(mailFrom, mailTo, async: false) ); }
public ConfigSimpleCqrs UseNsbEventBus() { var eventBus = new NsbEventBus(); ServiceLocator.Register <IEventBus>(eventBus); Configurer.RegisterSingleton <IEventBus>(eventBus); return(this); }
public ConfigSimpleCqrs UseLocalCommandBus() { var commandBus = ServiceLocator.Resolve <LocalCommandBus>(); ServiceLocator.Register <ICommandBus>(commandBus); Configurer.RegisterSingleton <ICommandBus>(commandBus); return(this); }
public object GetService(Type serviceType) { if (Configurer.HasComponent(serviceType)) { return(Builder.Build(serviceType)); } return(null); }
#pragma warning restore 0618 void ConfigureSubscriptionAuthorization() { var authType = TypesToScan.FirstOrDefault(t => typeof(IAuthorizeSubscriptions).IsAssignableFrom(t) && !t.IsInterface); if (authType != null) { Configurer.ConfigureComponent(authType, DependencyLifecycle.SingleInstance); } }
void ConfigureBehaviors() { Instance.ForAllTypes <IBehavior <HandlerInvocationContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall)); Instance.ForAllTypes <IBehavior <ReceiveLogicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall)); Instance.ForAllTypes <IBehavior <ReceivePhysicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall)); Instance.ForAllTypes <IBehavior <SendLogicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall)); Instance.ForAllTypes <IBehavior <SendLogicalMessagesContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall)); Instance.ForAllTypes <IBehavior <SendPhysicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall)); }
public static Configurer WithDefaultTargetsAndRules(this Configurer @this, string logTableName, string connectionString, string mailFrom, string mailTo, bool async = true, bool disableMailInDevelop = true) { @this.WithArkDefaultTargetsAndRules(logTableName, connectionString, mailFrom, mailTo, _isProduction(), async); if (disableMailInDevelop) { @this.DisableMailRuleWhenInVisualStudio(); } @this.ThrowInternalExceptionsInVisualStudio(); return(@this); }
public ConfigSimpleCqrs UseNsbCommandBus() { var config = new ConfigCommandBus(runtime); var commandBus = config.Configure(this); ServiceLocator.Register <ICommandBus>(commandBus); Configurer.RegisterSingleton <ICommandBus>(commandBus); return(this); }
public static Configurer WithDefaultTargets(this Configurer @this, string logTableName, string connectionString, string mailFrom, string mailTo, string smtpServer, int smtpPort, string smtpUserName, string smtpPassword, bool useSsl, bool async = true) { return(@this.WithConsoleTarget(async) .WithFileTarget(async) .WithDatabaseTarget(logTableName, connectionString, async) .WithMailTarget(mailFrom, mailTo, smtpServer, smtpPort, smtpUserName, smtpPassword, useSsl, async: false) ); }
public static WorldBuilder AddPhysics2DFeature(this WorldBuilder self, Func <ISetTimeStep, IConfigurationEnd> configure) { var configurer = new Configurer(); configure(configurer); // @formatter:off return(self.AddFeature(Name) .DependsOn() .Feature(CoreFeature.Name) .Feature(DestroyFeature.Name) .Feature(TickFeature.Name) .End() .Components <Game>() .Add <Position>() .Add <Velocity>() .Add <Damping>() .Add <Force>() .Add <MaxVelocity>() .Add <Mass>() .Add <Orientation>() .Add <AngularVelocity>() .Add <MaxAngularVelocity>() .Add <AngularDamping>() .Add <Torque>() .Add <Inertia>() .Add <BoundingShapes>() .Add <Collisions>() .End() .Components <Configuration>() .Add <TimeStep>() .Add <GlobalForce>() .End() .Components <Singletons>() .Add <Space>() .End() .Systems() .Setup((contexts, bus) => SetupSystem.Setup(contexts, configurer.TimeStep, configurer.SpatialDatabase)) .Update((contexts, bus) => AccelerateSystem.Update(contexts)) .Update((contexts, bus) => AngularAccelerateSystem.Update(contexts)) .Update((contexts, bus) => MoveSystem.Update(contexts)) .Update((contexts, bus) => RotateSystem.Update(contexts)) .Update((contexts, bus) => SpaceReindexSystem.Update(contexts)) .Update((contexts, bus) => FindCollisionsSystem.Update(contexts)) .Cleanup((contexts, bus) => SpatialDatabaseCleanupSystem.Cleanup(contexts)) .Cleanup((contexts, bus) => ReturnCollisionsListOnDestroySystem.Cleanup(contexts)) .Cleanup((contexts, bus) => ReturnShapesOnDestroySystem.Cleanup(contexts)) .End() .GlobalComponentNotifications <Game>() .AddAllNotifications <Position>() .AddAllNotifications <Orientation>() .End() .End()); // @formatter:on }
public void Ctor_SetsConfiguration() { //Arrange var config = new Configurer(); // Act var ex = new MissingConfigurationKeyException("Foo", config); // Assert Assert.That(ex.Configuration, Is.EqualTo(config.ToString())); }
public void Configure(Configure config) { Configurer = config.Configurer; Builder = config.Builder; runtime.Start(); ServiceLocator = runtime.ServiceLocator; ServiceLocator.Register(() => Builder.Build <IBus>()); Configurer.RegisterSingleton <ISimpleCqrsRuntime>(runtime); }
public static Configurer WithDefaultTargetsAndRulesFromCloudConfiguration(this Configurer @this, string logTableName, string mailFrom, string mailTo, bool async = true, bool disableMailInDevelop = true) { @this.WithDefaultTargetsFromCloudConfiguration(logTableName, mailFrom, mailTo, async); @this.WithDefaultRules(); if (disableMailInDevelop) { @this.DisableMailRuleWhenInVisualStudio(); } @this.ThrowInternalExceptionsInVisualStudio(); return(@this); }
protected Cell() { CellAboveIndex = -1; Configure = new Configurer(this); }
private void CheckBox_Unchecked(object sender, RoutedEventArgs e) { Configurer config = new Configurer(); config.UpdateConfig(new KeyValuePair<string, string>("AutoUpdatesEnabled", "false")); }