public static IBusControl ConfigureBus(MonitoredServices monitoringName = MonitoredServices.NotMonitored,
                                               Action <IRabbitMqBusFactoryConfigurator, IRabbitMqHost> registrationAction = null)
        {
            Log.Information("Configuring Bus uri={uri} user={user}", Settings.Default.RabbitMqUri, Settings.Default.RabbitMqUserName);

            return(MassTransit.Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                var host = cfg.Host(new Uri(Settings.Default.RabbitMqUri), hst =>
                {
                    hst.Username(Settings.Default.RabbitMqUserName);
                    hst.Password(Settings.Default.RabbitMqPassword);
                });
                if (monitoringName != MonitoredServices.NotMonitored)
                {
                    cfg.ReceiveEndpoint(host, string.Format(BusConstants.MonitoringServiceHeartbeatRequestQueue, monitoringName.ToString()),
                                        ec => { ec.Consumer(() => new HeartbeatConsumer(monitoringName.ToString())); });
                }

                registrationAction?.Invoke(cfg, host);
            }));
        }
        public static void ConfigureBus(ContainerBuilder builder, MonitoredServices monitoringName = MonitoredServices.NotMonitored, Action <IRabbitMqBusFactoryConfigurator, IComponentContext> registrationAction = null)
        {
            Log.Information("Configuring Bus uri={uri} user={user}", Settings.Default.RabbitMqUri, Settings.Default.RabbitMqUserName);

            // Configure Logging for Masstransit using Serilog
            MassTransit.Context.LogContext.ConfigureCurrentLogContext(new SerilogLoggerFactory(Log.Logger));

            builder.Register(ctx =>
            {
                return(MassTransit.Bus.Factory.CreateUsingRabbitMq(cfg =>
                {
                    cfg.Host(new Uri(Settings.Default.RabbitMqUri), hst =>
                    {
                        hst.Username(Settings.Default.RabbitMqUserName);
                        hst.Password(Settings.Default.RabbitMqPassword);
                    });
                    if (monitoringName != MonitoredServices.NotMonitored)
                    {
                        cfg.ReceiveEndpoint(string.Format(BusConstants.MonitoringServiceHeartbeatRequestQueue, monitoringName.ToString()),
                                            ec => { ec.Consumer(() => new HeartbeatConsumer(monitoringName.ToString())); });
                    }


                    var context = ctx.Resolve <IComponentContext>();
                    registrationAction?.Invoke(cfg, context);
                }));
            })
            .SingleInstance()
            .As <IBusControl>()
            .As <IBus>()
            .ExternallyOwned();
        }