Пример #1
0
        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);
        }
Пример #2
0
        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);
        }