public static BusBuilderConfiguration WithDefaultTimeout(this BusBuilderConfiguration configuration, TimeSpan defaultTimeout) { configuration.DefaultTimeout = new DefaultTimeoutSetting { Value = defaultTimeout }; return(configuration); }
public static BusBuilderConfiguration WithGlobalPrefix(this BusBuilderConfiguration configuration, string globalPrefix) { configuration.GlobalPrefix = new GlobalPrefixSetting { Value = globalPrefix }; return(configuration); }
public static BusBuilderConfiguration WithDefaultConcurrentHandlerLimit(this BusBuilderConfiguration configuration, int defaultConcurrentHandlerLimit) { configuration.ConcurrentHandlerLimit = new ConcurrentHandlerLimitSetting { Value = defaultConcurrentHandlerLimit }; return(configuration); }
public static BusBuilderConfiguration WithHeartbeatInterval(this BusBuilderConfiguration configuration, TimeSpan heartbeatInterval) { configuration.HeartbeatInterval = new HeartbeatIntervalSetting { Value = heartbeatInterval }; return(configuration); }
public static BusBuilderConfiguration WithConnectionString(this BusBuilderConfiguration configuration, string connectionString) { configuration.ConnectionString = new ConnectionStringSetting { Value = connectionString }; return(configuration); }
public static BusBuilderConfiguration WithDefaultMessageLockDuration(this BusBuilderConfiguration configuration, TimeSpan defaultLockDuration) { configuration.DefaultMessageLockDuration = new DefaultMessageLockDurationSetting { Value = defaultLockDuration }; return(configuration); }
public static BusBuilderConfiguration WithAutofacDefaults(this BusBuilderConfiguration configuration, IComponentContext componentContext) { return(configuration .WithTypesFrom(componentContext.Resolve <ITypeProvider>()) .WithDependencyResolver(componentContext.Resolve <IDependencyResolver>()) ); }
public static BusBuilderConfiguration WithServerConnectionCount(this BusBuilderConfiguration configuration, int serverConnectionCount) { configuration.ServerConnectionCount = new ServerConnectionCountSetting { Value = serverConnectionCount }; return(configuration); }
public static BusBuilderConfiguration WithDefaultMessageTimeToLive(this BusBuilderConfiguration configuration, TimeSpan timeToLive) { configuration.DefaultMessageTimeToLive = new DefaultMessageTimeToLiveSetting { Value = timeToLive }; return(configuration); }
public static BusBuilderConfiguration WithMaxDeliveryAttempts(this BusBuilderConfiguration configuration, int maxDeliveryAttempts) { configuration.MaxDeliveryAttempts = new MaxDeliveryAttemptSetting { Value = maxDeliveryAttempts }; return(configuration); }
public static BusBuilderConfiguration WithMinimumThreadPoolThreads(this BusBuilderConfiguration configuration, int minimumThreadPoolThreads) { configuration.MinimumThreadPoolThreads = new MinimumThreadPoolThreadsSetting { Value = minimumThreadPoolThreads }; return(configuration); }
public static BusBuilderConfiguration WithAutoDeleteOnIdle(this BusBuilderConfiguration configuration, TimeSpan autoDeleteOnIdle) { configuration.AutoDeleteOnIdle = new AutoDeleteOnIdleSetting { Value = autoDeleteOnIdle }; return(configuration); }
public static BusBuilderConfiguration WithGlobalOutboundInterceptorTypes(this BusBuilderConfiguration configuration, params Type[] interceptorTypes) { configuration.GlobalOutboundInterceptorTypes = new GlobalOutboundInterceptorTypesSetting { Value = interceptorTypes }; return(configuration); }
private static void CreateCommandMessagePumps(BusBuilderConfiguration configuration, MessagingFactory messagingFactory, List<IMessagePump> messagePumps) { foreach (var commandType in configuration.CommandTypes) { var pump = new CommandMessagePump(messagingFactory, configuration.CommandBroker, commandType, configuration.Logger); messagePumps.Add(pump); } }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); configuration.AssertConfigurationIsValid(); var container = new PoorMansIoC(); container.RegisterPropertiesFromConfigurationObject(configuration); logger.Debug("Creating message pumps..."); var messagePumpsManager = new MessagePumpsManager( container.Resolve <ResponseMessagePumpFactory>().Create(), container.Resolve <RequestMessagePumpsFactory>().CreateAll(), container.Resolve <CommandMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve <CompetingEventMessagePumpsFactory>().CreateAll()); logger.Debug("Message pumps are all created."); var bus = container.ResolveWithOverrides <Bus>(messagePumpsManager); container.Resolve <PropertyInjector>().Bus = bus; bus.Starting += (s, e) => { Task.Run(async() => { try { await container.Resolve <INimbusTransport>().TestConnection(); await CleanNamespace(container, logger); } catch (Exception ex) { logger.Error(ex, "Failed to establish connection to underlying transport: {Message}", ex.Message); throw; } }).Wait(); }; bus.Disposing += (s, e) => { Task.Run(async() => { await CleanNamespace(container, logger); container.Dispose(); }).Wait(); }; logger.Info("Bus built. Job done!"); return(bus); }
public static BusBuilderConfiguration WithDefaults(this BusBuilderConfiguration configuration, ITypeProvider typeProvider) { return(configuration .WithTypesFrom(typeProvider) .WithDependencyResolver(new DependencyResolver(typeProvider)) .WithRouter(new DestinationPerMessageTypeRouter()) .WithCompressor(new NullCompressor()) .WithLogger(new NullLogger()) ); }
/// <summary> /// </summary> /// <param name="configuration"></param> /// <param name="applicationName"> /// This should be unique for your application (e.g. Foo.exe) but should be the same across /// all instances of your application. /// </param> /// <param name="instanceName"> /// This should be unique across ALL instances of your application. Use your hostname if you're /// stuck. /// </param> /// <returns></returns> public static BusBuilderConfiguration WithNames(this BusBuilderConfiguration configuration, string applicationName, string instanceName) { configuration.ApplicationName = new ApplicationNameSetting { Value = applicationName }; configuration.InstanceName = new InstanceNameSetting { Value = instanceName }; return(configuration); }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); configuration.AssertConfigurationIsValid(); var container = new PoorMansIoC(); container.RegisterPropertiesFromConfigurationObject(configuration); logger.Debug("Creating message pumps..."); var messagePumpsManager = new MessagePumpsManager( container.Resolve<ResponseMessagePumpFactory>().Create(), container.Resolve<RequestMessagePumpsFactory>().CreateAll(), container.Resolve<CommandMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll()); logger.Debug("Message pumps are all created."); var bus = container.ResolveWithOverrides<Bus>(messagePumpsManager); container.Resolve<PropertyInjector>().Bus = bus; bus.Starting += (s, e) => { Task.Run(async () => { try { await container.Resolve<INimbusTransport>().TestConnection(); await CleanNamespace(container, logger); } catch (Exception ex) { logger.Error(ex, "Failed to establish connection to underlying transport: {Message}", ex.Message); throw; } }).Wait(); }; bus.Disposing += (s, e) => { Task.Run(async () => { await CleanNamespace(container, logger); container.Dispose(); }).Wait(); }; logger.Info("Bus built. Job done!"); return bus; }
internal static Bus Build(BusBuilderConfiguration configuration) { var replyQueueName = string.Format("InputQueue.{0}.{1}", configuration.ApplicationName, configuration.InstanceName); var namespaceManager = NamespaceManager.CreateFromConnectionString(configuration.ConnectionString); var messagingFactory = MessagingFactory.CreateFromConnectionString(configuration.ConnectionString); var messagePumps = new List<IMessagePump>(); var queueManager = new QueueManager(namespaceManager, messagingFactory, configuration.MaxDeliveryAttempts); var clock = new SystemClock(); var requestResponseCorrelator = new RequestResponseCorrelator(clock); var messageSenderFactory = new MessageSenderFactory(messagingFactory); var topicClientFactory = new TopicClientFactory(messagingFactory); var commandSender = new BusCommandSender(messageSenderFactory); var requestSender = new BusRequestSender(messageSenderFactory, replyQueueName, requestResponseCorrelator, clock, configuration.DefaultTimeout); var multicastRequestSender = new BusMulticastRequestSender(topicClientFactory, replyQueueName, requestResponseCorrelator, clock); var eventSender = new BusEventSender(topicClientFactory); if (configuration.Debugging.RemoveAllExistingNamespaceElements) { RemoveAllExistingNamespaceElements(namespaceManager); } var queueCreationTasks = new[] { Task.Run(() => CreateMyInputQueue(queueManager, replyQueueName)), Task.Run(() => CreateCommandQueues(configuration, queueManager)), Task.Run(() => CreateRequestQueues(configuration, queueManager)), Task.Run(() => CreateMulticastRequestTopics(configuration, queueManager)), Task.Run(() => CreateEventTopics(configuration, queueManager)), }; Task.WaitAll(queueCreationTasks); //FIXME do these in parallel CreateResponseMessagePump(configuration, messagingFactory, replyQueueName, requestResponseCorrelator, messagePumps); CreateCommandMessagePumps(configuration, messagingFactory, messagePumps); CreateRequestMessagePumps(configuration, messagingFactory, messagePumps); CreateMulticastRequestMessagePumps(configuration, queueManager, messagingFactory, messagePumps); CreateMulticastEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps); CreateCompetingEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps); var commandDeadLetterQueue = new DeadLetterQueue(queueManager); var requestDeadLetterQueue = new DeadLetterQueue(queueManager); var deadLetterQueues = new DeadLetterQueues(commandDeadLetterQueue, requestDeadLetterQueue); var bus = new Bus(commandSender, requestSender, multicastRequestSender, eventSender, messagePumps, deadLetterQueues); return bus; }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); var container = new PoorMansIoC(); foreach (var prop in configuration.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance)) { var value = prop.GetValue(configuration); if (value == null) continue; container.Register(value); } container.Register<Func<NamespaceManager>>(c => () => NamespaceManager.CreateFromConnectionString(c.Resolve<ConnectionStringSetting>())); container.Register<Func<MessagingFactory>>(c => () => MessagingFactory.CreateFromConnectionString(c.Resolve<ConnectionStringSetting>())); if (configuration.Debugging.RemoveAllExistingNamespaceElements) { RemoveAllExistingNamespaceElements(container.Resolve<Func<NamespaceManager>>(), logger); } logger.Debug("Creating message pumps and subscriptions."); var messagePumps = new List<IMessagePump>(); messagePumps.Add(container.Resolve<ResponseMessagePumpFactory>().Create()); messagePumps.AddRange(container.Resolve<CommandMessagePumpsFactory>().CreateAll()); messagePumps.AddRange(container.Resolve<RequestMessagePumpsFactory>().CreateAll()); messagePumps.AddRange(container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll()); messagePumps.AddRange(container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll()); messagePumps.AddRange(container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll()); logger.Debug("Message pumps and subscriptions are all created."); var bus = new Bus(container.Resolve<ILogger>(), container.Resolve<ICommandSender>(), container.Resolve<IRequestSender>(), container.Resolve<IMulticastRequestSender>(), container.Resolve<IEventSender>(), messagePumps, container.Resolve<DeadLetterQueues>()); bus.Disposing += (sender, args) => container.Dispose(); logger.Debug("Bus built. Job done!"); return bus; }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); configuration.AssertConfigurationIsValid(); var container = new PoorMansIoC(); container.RegisterPropertiesFromConfigurationObject(configuration); logger.Debug("Creating message pumps..."); var messagePumpsManager = new MessagePumpsManager( container.Resolve <ResponseMessagePumpFactory>().Create(), container.Resolve <RequestMessagePumpsFactory>().CreateAll(), container.Resolve <CommandMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve <CompetingEventMessagePumpsFactory>().CreateAll()); logger.Debug("Message pumps are all created."); var bus = container.ResolveWithOverrides <Bus>(messagePumpsManager); container.Resolve <PropertyInjector>().Bus = bus; bus.Starting += delegate { container.Resolve <INimbusTransport>().TestConnection().Wait(); var removeAllExistingElements = container.Resolve <RemoveAllExistingNamespaceElementsSetting>(); if (removeAllExistingElements) { logger.Debug("Removing all existing namespace elements. IMPORTANT: This should only be done in your regression test suites."); var cleanser = container.Resolve <INamespaceCleanser>(); cleanser.RemoveAllExistingNamespaceElements().Wait(); } }; bus.Disposing += delegate { container.Dispose(); }; logger.Info("Bus built. Job done!"); return(bus); }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); configuration.AssertConfigurationIsValid(); var container = new PoorMansIoC(); container.RegisterPropertiesFromConfigurationObject(configuration); logger.Debug("Creating message pumps..."); var messagePumpsManager = new MessagePumpsManager( container.Resolve<ResponseMessagePumpFactory>().Create(), container.Resolve<RequestMessagePumpsFactory>().CreateAll(), container.Resolve<CommandMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll()); logger.Debug("Message pumps are all created."); var bus = container.ResolveWithOverrides<Bus>(messagePumpsManager); container.Resolve<PropertyInjector>().Bus = bus; bus.Starting += delegate { container.Resolve<INimbusTransport>().TestConnection().Wait(); var removeAllExistingElements = container.Resolve<RemoveAllExistingNamespaceElementsSetting>(); if (removeAllExistingElements) { logger.Debug("Removing all existing namespace elements. IMPORTANT: This should only be done in your regression test suites."); var cleanser = container.Resolve<INamespaceCleanser>(); cleanser.RemoveAllExistingNamespaceElements().Wait(); } }; bus.Disposing += delegate { container.Dispose(); }; logger.Info("Bus built. Job done!"); return bus; }
public static BusBuilderConfiguration WithDebugOptions(this BusBuilderConfiguration configuration, Func <DebugConfiguration, DebugConfiguration> debugConfiguration) { debugConfiguration(configuration.Debug); return(configuration); }
private static void CreateMulticastEventMessagePumps(BusBuilderConfiguration configuration, IQueueManager queueManager, MessagingFactory messagingFactory, ICollection<IMessagePump> messagePumps, ILogger logger) { logger.Debug("Creating multicast event message pumps"); var eventTypes = configuration.MulticastEventHandlerTypes.SelectMany(ht => ht.GetGenericInterfacesClosing(typeof (IHandleMulticastEvent<>))) .Select(gi => gi.GetGenericArguments().Single()) .OrderBy(t => t.FullName) .Distinct() .ToArray(); foreach (var eventType in eventTypes) { logger.Debug("Registering Message Pump for Event type {0}", eventType.Name); var myInstanceSubscriptionName = String.Format("{0}.{1}", configuration.InstanceName, configuration.ApplicationName); queueManager.EnsureSubscriptionExists(eventType, myInstanceSubscriptionName); var pump = new MulticastEventMessagePump(messagingFactory, configuration.MulticastEventBroker, eventType, myInstanceSubscriptionName, configuration.Logger, configuration.DefaultBatchSize); messagePumps.Add(pump); } }
public static BusBuilderConfiguration WithConnectionStringFromFile(this BusBuilderConfiguration configuration, string filename) { var connectionString = File.ReadAllText(filename).Trim(); return(configuration.WithConnectionString(connectionString)); }
private static void CreateRequestQueues(BusBuilderConfiguration configuration, QueueManager queueManager, ILogger logger) { logger.Debug("Creating request queues"); configuration.RequestTypes .AsParallel() .Do(queueManager.EnsureQueueExists) .Done(); }
public static BusBuilderConfiguration WithDeliveryRetryStrategy(this BusBuilderConfiguration configuration, IDeliveryRetryStrategy deliveryRetryStrategy) { configuration.DeliveryRetryStrategy = deliveryRetryStrategy; return(configuration); }
public static BusBuilderConfiguration WithDependencyResolver(this BusBuilderConfiguration configuration, IDependencyResolver dependencyResolver) { configuration.DependencyResolver = dependencyResolver; return(configuration); }
private static void CreateRequestMessagePumps(BusBuilderConfiguration configuration, MessagingFactory messagingFactory, List<IMessagePump> messagePumps, ILogger logger) { logger.Debug("Creating request message pumps"); var requestTypes = configuration.RequestHandlerTypes.SelectMany(ht => ht.GetGenericInterfacesClosing(typeof(IHandleRequest<,>))) .Select(gi => gi.GetGenericArguments().First()) .OrderBy(t => t.FullName) .Distinct() .ToArray(); foreach (var requestType in requestTypes) { logger.Debug("Registering Message Pump for Request type {0}", requestType.Name); var pump = new RequestMessagePump(messagingFactory, configuration.RequestBroker, requestType, configuration.Logger, configuration.DefaultBatchSize); messagePumps.Add(pump); } }
private static void CreateRequestMessagePumps(BusBuilderConfiguration configuration, MessagingFactory messagingFactory, List<IMessagePump> messagePumps) { foreach (var requestType in configuration.RequestTypes) { var pump = new RequestMessagePump(messagingFactory, configuration.RequestBroker, requestType, configuration.Logger); messagePumps.Add(pump); } }
private static void CreateResponseMessagePump(BusBuilderConfiguration configuration, MessagingFactory messagingFactory, string replyQueueName, RequestResponseCorrelator requestResponseCorrelator, ICollection<IMessagePump> messagePumps) { var responseMessagePump = new ResponseMessagePump(messagingFactory, replyQueueName, requestResponseCorrelator, configuration.Logger); messagePumps.Add(responseMessagePump); }
public static BusBuilderConfiguration WithSerializer(this BusBuilderConfiguration configuration, ISerializer serializer) { configuration.Serializer = serializer; return(configuration); }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); var container = new PoorMansIoC(); RegisterPropertiesFromConfigurationObject(container, configuration); RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration); RegisterPropertiesFromConfigurationObject(container, configuration.Debugging); var namespaceManagerRoundRobin = new RoundRobin<NamespaceManager>( container.Resolve<ServerConnectionCountSetting>(), () => { var namespaceManager = NamespaceManager.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>()); namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(120); return namespaceManager; }, nsm => false, nsm => { }); container.Register<Func<NamespaceManager>>(c => namespaceManagerRoundRobin.GetNext); var messagingFactoryRoundRobin = new RoundRobin<MessagingFactory>( container.Resolve<ServerConnectionCountSetting>(), () => { var messagingFactory = MessagingFactory.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>()); messagingFactory.PrefetchCount = container.Resolve<ConcurrentHandlerLimitSetting>(); return messagingFactory; }, mf => mf.IsBorked(), mf => { }); container.Register<Func<MessagingFactory>>(c => messagingFactoryRoundRobin.GetNext); if (configuration.Debugging.RemoveAllExistingNamespaceElements) { var namespaceCleanser = container.Resolve<NamespaceCleanser>(); namespaceCleanser.RemoveAllExistingNamespaceElements().Wait(); } logger.Debug("Creating message pumps..."); var messagePumps = new MessagePumpsManager( container.Resolve<ResponseMessagePumpFactory>().Create(), container.Resolve<RequestMessagePumpsFactory>().CreateAll(), container.Resolve<CommandMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll(), container.Resolve<INimbusTaskFactory>()); logger.Debug("Message pumps are all created."); var bus = new Bus(container.Resolve<ILogger>(), container.Resolve<ICommandSender>(), container.Resolve<IRequestSender>(), container.Resolve<IMulticastRequestSender>(), container.Resolve<IEventSender>(), messagePumps, container.Resolve<DeadLetterQueues>(), container.Resolve<INimbusTaskFactory>(), container.Resolve<IHeartbeat>()); bus.Starting += delegate { container.Resolve<AzureQueueManager>().WarmUp(); container.Resolve<PropertyInjector>().Bus = bus; }; bus.Disposing += delegate { container.Dispose(); }; logger.Info("Bus built. Job done!"); return bus; }
private static void CreateCommandQueues(BusBuilderConfiguration configuration, QueueManager queueManager) { configuration.CommandTypes .AsParallel() .Do(queueManager.EnsureQueueExists) .Done(); }
private static void CreateCompetingEventMessagePumps(BusBuilderConfiguration configuration, IQueueManager queueManager, MessagingFactory messagingFactory, ICollection<IMessagePump> messagePumps) { var eventTypes = configuration.CompetingEventHandlerTypes.SelectMany(ht => ht.GetGenericInterfacesClosing(typeof (IHandleCompetingEvent<>))) .Select(gi => gi.GetGenericArguments().Single()) .OrderBy(t => t.FullName) .Distinct() .ToArray(); foreach (var eventType in eventTypes) { var applicationSharedSubscriptionName = String.Format("{0}", configuration.ApplicationName); queueManager.EnsureSubscriptionExists(eventType, applicationSharedSubscriptionName); var pump = new CompetingEventMessagePump(messagingFactory, configuration.CompetingEventBroker, eventType, applicationSharedSubscriptionName, configuration.Logger); messagePumps.Add(pump); } }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); var container = new PoorMansIoC(); RegisterPropertiesFromConfigurationObject(container, configuration); RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration); RegisterPropertiesFromConfigurationObject(container, configuration.Debugging); var namespaceManagerRoundRobin = new RoundRobin <NamespaceManager>( container.Resolve <ServerConnectionCountSetting>(), () => { var namespaceManager = NamespaceManager.CreateFromConnectionString(container.Resolve <ConnectionStringSetting>()); namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(120); return(namespaceManager); }, nsm => false, nsm => { }); container.Register <Func <NamespaceManager> >(c => namespaceManagerRoundRobin.GetNext); var messagingFactoryRoundRobin = new RoundRobin <MessagingFactory>( container.Resolve <ServerConnectionCountSetting>(), () => { var messagingFactory = MessagingFactory.CreateFromConnectionString(container.Resolve <ConnectionStringSetting>()); messagingFactory.PrefetchCount = container.Resolve <ConcurrentHandlerLimitSetting>(); return(messagingFactory); }, mf => mf.IsBorked(), mf => { }); container.Register <Func <MessagingFactory> >(c => messagingFactoryRoundRobin.GetNext); if (configuration.Debugging.RemoveAllExistingNamespaceElements) { var namespaceCleanser = container.Resolve <NamespaceCleanser>(); namespaceCleanser.RemoveAllExistingNamespaceElements().Wait(); } logger.Debug("Creating message pumps..."); var messagePumps = new MessagePumpsManager( container.Resolve <ResponseMessagePumpFactory>().Create(), container.Resolve <RequestMessagePumpsFactory>().CreateAll(), container.Resolve <CommandMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve <CompetingEventMessagePumpsFactory>().CreateAll(), container.Resolve <INimbusTaskFactory>()); logger.Debug("Message pumps are all created."); var bus = new Bus(container.Resolve <ILogger>(), container.Resolve <ICommandSender>(), container.Resolve <IRequestSender>(), container.Resolve <IMulticastRequestSender>(), container.Resolve <IEventSender>(), messagePumps, container.Resolve <DeadLetterQueues>(), container.Resolve <INimbusTaskFactory>(), container.Resolve <IHeartbeat>()); bus.Starting += delegate { container.Resolve <AzureQueueManager>().WarmUp(); container.Resolve <PropertyInjector>().Bus = bus; }; bus.Disposing += delegate { container.Dispose(); }; logger.Info("Bus built. Job done!"); return(bus); }
public static BusBuilderConfiguration WithTransport(this BusBuilderConfiguration configuration, TransportConfiguration transportConfiguration) { configuration.Transport = transportConfiguration; return(configuration); }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); var replyQueueName = string.Format("InputQueue.{0}.{1}", configuration.ApplicationName, configuration.InstanceName); var namespaceManager = NamespaceManager.CreateFromConnectionString(configuration.ConnectionString); var versionInfo = namespaceManager.GetVersionInfo(); var messagingFactory = MessagingFactory.CreateFromConnectionString(configuration.ConnectionString); var messagePumps = new List<IMessagePump>(); var queueManager = new QueueManager(namespaceManager, messagingFactory, configuration.MaxDeliveryAttempts, logger); var clock = new SystemClock(); var requestResponseCorrelator = new RequestResponseCorrelator(clock, logger); var messageSenderFactory = new MessageSenderFactory(messagingFactory); var topicClientFactory = new TopicClientFactory(messagingFactory); var commandSender = new BusCommandSender(messageSenderFactory, clock, configuration.CommandTypes); var requestSender = new BusRequestSender(messageSenderFactory, replyQueueName, requestResponseCorrelator, clock, configuration.DefaultTimeout, configuration.RequestTypes, logger); var multicastRequestSender = new BusMulticastRequestSender(topicClientFactory, replyQueueName, requestResponseCorrelator, clock, configuration.RequestTypes); var eventSender = new BusEventSender(topicClientFactory, configuration.EventTypes); if (configuration.Debugging.RemoveAllExistingNamespaceElements) { RemoveAllExistingNamespaceElements(namespaceManager, logger); } logger.Debug("Creating queues and topics"); var queueCreationTasks = new[] { Task.Run(() => CreateMyInputQueue(queueManager, replyQueueName, logger)), Task.Run(() => CreateCommandQueues(configuration, queueManager, logger)), Task.Run(() => CreateRequestQueues(configuration, queueManager, logger)), Task.Run(() => CreateMulticastRequestTopics(configuration, queueManager, logger)), Task.Run(() => CreateEventTopics(configuration, queueManager, logger)) }; Task.WaitAll(queueCreationTasks); logger.Debug("Queues and topics are all created."); logger.Debug("Creating message pumps and subscriptions."); var messagePumpCreationTasks = new[] { Task.Run(() => CreateResponseMessagePump(configuration, messagingFactory, replyQueueName, requestResponseCorrelator, messagePumps, logger)), Task.Run(() => CreateCommandMessagePumps(configuration, messagingFactory, messagePumps, logger)), Task.Run(() => CreateRequestMessagePumps(configuration, messagingFactory, messagePumps, logger)), Task.Run(() => CreateMulticastRequestMessagePumps(configuration, queueManager, messagingFactory, messagePumps, logger)), Task.Run(() => CreateMulticastEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps, logger)), Task.Run(() => CreateCompetingEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps, logger)) }; messagePumpCreationTasks.WaitAll(); logger.Debug("Message pumps and subscriptions are all created."); var commandDeadLetterQueue = new DeadLetterQueue(queueManager); var requestDeadLetterQueue = new DeadLetterQueue(queueManager); var deadLetterQueues = new DeadLetterQueues(commandDeadLetterQueue, requestDeadLetterQueue); var bus = new Bus(commandSender, requestSender, multicastRequestSender, eventSender, messagePumps, deadLetterQueues); logger.Debug("Bus built. Job done!"); return bus; }
private static void CreateMulticastRequestTopics(BusBuilderConfiguration configuration, QueueManager queueManager) { configuration.RequestTypes .AsParallel() .Do(queueManager.EnsureTopicExists) .Done(); }
public static BusBuilderConfiguration WithTypesFrom(this BusBuilderConfiguration configuration, ITypeProvider typeProvider) { configuration.TypeProvider = typeProvider; return(configuration); }
public static BusBuilderConfiguration WithEnableDeadLetteringOnMessageExpiration(this BusBuilderConfiguration configuration, bool enableDeadLettering) { configuration.EnableDeadLetteringOnMessageExpiration = new EnableDeadLetteringOnMessageExpirationSetting { Value = enableDeadLettering }; return(configuration); }
public static BusBuilderConfiguration WithRouter(this BusBuilderConfiguration configuration, IRouter router) { configuration.Router = router; return(configuration); }
private static void CreateMulticastRequestMessagePumps(BusBuilderConfiguration configuration, QueueManager queueManager, MessagingFactory messagingFactory, List<IMessagePump> messagePumps) { var requestTypes = configuration.RequestHandlerTypes.SelectMany(ht => ht.GetGenericInterfacesClosing(typeof (IHandleRequest<,>))) .Select(gi => gi.GetGenericArguments().First()) .OrderBy(t => t.FullName) .Distinct() .ToArray(); foreach (var requestType in requestTypes) { var applicationSharedSubscriptionName = String.Format("{0}", configuration.ApplicationName); queueManager.EnsureSubscriptionExists(requestType, applicationSharedSubscriptionName); var pump = new MulticastRequestMessagePump(messagingFactory, configuration.MulticastRequestBroker, requestType, applicationSharedSubscriptionName, configuration.Logger); messagePumps.Add(pump); } }
private static void CreateEventTopics(BusBuilderConfiguration configuration, QueueManager queueManager, ILogger logger) { logger.Debug("Creating event topics"); configuration.EventTypes .AsParallel() .Do(queueManager.EnsureTopicExists) .Done(); }
public static BusBuilderConfiguration WithLogger(this BusBuilderConfiguration configuration, ILogger logger) { configuration.Logger = logger; return(configuration); }
public static BusBuilderConfiguration WithLargeMessageStorage(this BusBuilderConfiguration configuration, Action <LargeMessageStorageConfiguration> configurationAction) { configurationAction(configuration.LargeMessageStorageConfiguration); return(configuration); }
/// <summary> /// Log to the Serilog <see cref="Serilog.Log" /> class. /// </summary> /// <param name="configuration">The bus configuration to apply the logger to.</param> /// <returns>Bus configuration.</returns> public static BusBuilderConfiguration WithSerilogLogger(this BusBuilderConfiguration configuration) { return(configuration .WithLogger(new SerilogStaticLogger())); }