public void Register(ContainerBuilder builder) { builder.RegisterModule(new LoggingModule()); builder.RegisterBuildCallback( c => { // set up loggers for Dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("EdgeHub")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); bool optimizeForPerformance = this.configuration.GetValue("OptimizeForPerformance", true); (bool isEnabled, bool usePersistentStorage, StoreAndForwardConfiguration config, string storagePath)storeAndForward = this.GetStoreAndForwardConfiguration(); IConfiguration configuration = this.configuration.GetSection("experimentalFeatures"); ExperimentalFeatures experimentalFeatures = ExperimentalFeatures.Create(configuration); this.RegisterCommonModule(builder, optimizeForPerformance, storeAndForward); this.RegisterRoutingModule(builder, storeAndForward, experimentalFeatures); this.RegisterMqttModule(builder, storeAndForward, optimizeForPerformance); this.RegisterAmqpModule(builder); builder.RegisterModule(new HttpModule()); }
public void Register(ContainerBuilder builder) { builder.RegisterModule(new LoggingModule()); builder.RegisterBuildCallback( c => { // set up loggers for Dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("EdgeHub")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); bool optimizeForPerformance = this.configuration.GetValue("OptimizeForPerformance", true); (bool isEnabled, bool usePersistentStorage, StoreAndForwardConfiguration config, string storagePath, bool useBackupAndRestore, Option <string> storageBackupPath, Option <ulong> storageMaxTotalWalSize, Option <StorageLogLevel> storageLogLevel)storeAndForward = this.GetStoreAndForwardConfiguration(); IConfiguration configuration = this.configuration.GetSection("experimentalFeatures"); ExperimentalFeatures experimentalFeatures = ExperimentalFeatures.Create(configuration, Logger.Factory.CreateLogger("EdgeHub")); MetricsListenerConfig listenerConfig = experimentalFeatures.EnableMetrics ? MetricsListenerConfig.Create(this.configuration.GetSection("metrics:listener")) : new MetricsListenerConfig(); MetricsConfig metricsConfig = new MetricsConfig(experimentalFeatures.EnableMetrics, listenerConfig); this.RegisterCommonModule(builder, optimizeForPerformance, storeAndForward, metricsConfig); this.RegisterRoutingModule(builder, storeAndForward, experimentalFeatures); this.RegisterMqttModule(builder, storeAndForward, optimizeForPerformance); this.RegisterAmqpModule(builder); builder.RegisterModule(new HttpModule()); }
public void Register(ContainerBuilder builder) { builder.RegisterModule(new LoggingModule()); builder.RegisterBuildCallback( c => { // set up loggers for Dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("EdgeHub")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); bool optimizeForPerformance = this.configuration.GetValue("OptimizeForPerformance", true); (bool isEnabled, bool usePersistentStorage, StoreAndForwardConfiguration config, string storagePath, bool useBackupAndRestore, Option <string> storageBackupPath, Option <ulong> storageMaxTotalWalSize, Option <StorageLogLevel> storageLogLevel)storeAndForward = this.GetStoreAndForwardConfiguration(); IConfiguration configuration = this.configuration.GetSection("experimentalFeatures"); ExperimentalFeatures experimentalFeatures = ExperimentalFeatures.Create(configuration, Logger.Factory.CreateLogger("EdgeHub")); // Temporarly make metrics default to off for windows. This is only until the dotnet 3.1 work is completed // This temp fix is needed to fix all e2e tests since edgehub currently crashes MetricsConfig metricsConfig = new MetricsConfig(this.configuration.GetSection("metrics:listener"), !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); this.RegisterCommonModule(builder, optimizeForPerformance, storeAndForward, metricsConfig); this.RegisterRoutingModule(builder, storeAndForward, experimentalFeatures); this.RegisterMqttModule(builder, storeAndForward, optimizeForPerformance); this.RegisterAmqpModule(builder); builder.RegisterModule(new HttpModule()); }
public void Register(ContainerBuilder builder) { builder.RegisterModule(new LoggingModule()); builder.RegisterBuildCallback( c => { // set up loggers for Dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("EdgeHub")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); bool optimizeForPerformance = this.configuration.GetValue("OptimizeForPerformance", true); StoreAndForward storeAndForward = this.GetStoreAndForwardConfiguration(); IConfiguration experimentalFeaturesConfig = this.configuration.GetSection(Constants.ConfigKey.ExperimentalFeatures); ExperimentalFeatures experimentalFeatures = ExperimentalFeatures.Create(experimentalFeaturesConfig, Logger.Factory.CreateLogger("EdgeHub")); MetricsConfig metricsConfig = new MetricsConfig(this.configuration.GetSection("metrics:listener")); bool nestedEdgeEnabled = this.configuration.GetValue <bool>(Constants.ConfigKey.NestedEdgeEnabled, true); if (!Enum.TryParse(this.configuration.GetValue("AuthenticationMode", string.Empty), true, out AuthenticationMode authenticationMode)) { authenticationMode = AuthenticationMode.Scope; } bool trackDeviceState = authenticationMode == AuthenticationMode.Scope && this.configuration.GetValue("TrackDeviceState", true); string proxyModuleId = this.configuration.GetValue("ApiProxyModuleId", Core.Constants.DefaultApiProxyId); this.RegisterCommonModule(builder, optimizeForPerformance, storeAndForward, metricsConfig, nestedEdgeEnabled, authenticationMode); this.RegisterRoutingModule(builder, storeAndForward, experimentalFeatures, nestedEdgeEnabled, authenticationMode == AuthenticationMode.Scope, trackDeviceState); this.RegisterMqttModule(builder, storeAndForward, optimizeForPerformance, experimentalFeatures); this.RegisterAmqpModule(builder); builder.RegisterModule(new HttpModule(this.iotHubHostname, this.edgeDeviceId, proxyModuleId)); if (experimentalFeatures.EnableMqttBroker) { var authConfig = this.configuration.GetSection("authAgentSettings"); builder.RegisterModule(new AuthModule(authConfig)); var mqttBrokerConfig = this.configuration.GetSection("mqttBrokerSettings"); builder.RegisterModule(new MqttBrokerModule(mqttBrokerConfig)); } }
public static IAppBuilder Bootstrap(IAppBuilder app, ApplicationConfiguration config) { config.Register = BlackCoffeeTalk.Service.Configuration.Register; config.ConfigureModel = BlackCoffeeTalk.Service.Configuration.ConfigureModel; app.Properties[ApplicationConfiguration.Key] = config; app.UseCors(CorsOptions.AllowAll); app.UseNLog(); var logger = app.CreateLogger <Application>(); var loggerEventListener = new LoggerEventListener(logger); loggerEventListener.EnableEvents(config.EventSource, EventLevel.LogAlways, (EventKeywords)long.MaxValue); app.Map("/v2", ApplicationV2.Configure); app.Map("", ConfigureSwagger); return(app); }
public void Register(ContainerBuilder builder) { builder.RegisterModule(new LoggingModule()); builder.RegisterBuildCallback( c => { // set up loggers for Dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("EdgeHub")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); bool optimizeForPerformance = this.configuration.GetValue("OptimizeForPerformance", true); StoreAndForward storeAndForward = this.GetStoreAndForwardConfiguration(); IConfiguration experimentalFeaturesConfig = this.configuration.GetSection(Constants.ConfigKey.ExperimentalFeatures); ExperimentalFeatures experimentalFeatures = ExperimentalFeatures.Create(experimentalFeaturesConfig, Logger.Factory.CreateLogger("EdgeHub")); MetricsConfig metricsConfig = new MetricsConfig(this.configuration.GetSection("metrics:listener")); this.RegisterCommonModule(builder, optimizeForPerformance, storeAndForward, metricsConfig, experimentalFeatures); this.RegisterRoutingModule(builder, storeAndForward, experimentalFeatures); this.RegisterMqttModule(builder, storeAndForward, optimizeForPerformance, experimentalFeatures); this.RegisterAmqpModule(builder); builder.RegisterModule(new HttpModule(this.iotHubHostname)); if (experimentalFeatures.EnableMqttBroker) { var authConfig = this.configuration.GetSection("authAgentSettings"); builder.RegisterModule(new AuthModule(authConfig)); var mqttBrokerConfig = this.configuration.GetSection("mqttBrokerSettings"); builder.RegisterModule(new MqttBrokerModule(mqttBrokerConfig)); } }
public void Register(ContainerBuilder builder) { const int ConnectionPoolSize = 10; string edgeHubConnectionString = $"{this.configuration[Service.Constants.ConfigKey.IotHubConnectionString]};ModuleId=$edgeHub"; Client.IotHubConnectionStringBuilder iotHubConnectionStringBuilder = Client.IotHubConnectionStringBuilder.Create(edgeHubConnectionString); var topics = new MessageAddressConversionConfiguration(this.inboundTemplates, this.outboundTemplates); builder.RegisterModule(new LoggingModule()); var mqttSettingsConfiguration = new Mock <IConfiguration>(); mqttSettingsConfiguration.Setup(c => c.GetSection(It.IsAny <string>())).Returns(Mock.Of <IConfigurationSection>(s => s.Value == null)); builder.RegisterBuildCallback( c => { // set up loggers for dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("ProtocolGateway")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); var versionInfo = new VersionInfo("v1", "b1", "c1"); var storeAndForwardConfiguration = new StoreAndForwardConfiguration(-1); builder.RegisterModule( new CommonModule( string.Empty, iotHubConnectionStringBuilder.HostName, iotHubConnectionStringBuilder.DeviceId, iotHubConnectionStringBuilder.ModuleId, string.Empty, Option.None <string>(), AuthenticationMode.CloudAndScope, Option.Some(edgeHubConnectionString), false, false, string.Empty, Option.None <string>(), TimeSpan.FromHours(1), false, this.trustBundle)); builder.RegisterModule( new RoutingModule( iotHubConnectionStringBuilder.HostName, iotHubConnectionStringBuilder.DeviceId, iotHubConnectionStringBuilder.ModuleId, Option.Some(edgeHubConnectionString), this.routes, false, storeAndForwardConfiguration, ConnectionPoolSize, false, versionInfo, Option.Some(UpstreamProtocol.Amqp), TimeSpan.FromSeconds(5), 101, TimeSpan.FromSeconds(3600), true, TimeSpan.FromSeconds(20))); builder.RegisterModule(new HttpModule()); builder.RegisterModule(new MqttModule(mqttSettingsConfiguration.Object, topics, this.serverCertificate, false, false, false)); builder.RegisterModule(new AmqpModule("amqps", 5671, this.serverCertificate, iotHubConnectionStringBuilder.HostName, true)); }
public void Register(ContainerBuilder builder) { const int ConnectionPoolSize = 10; string edgeHubConnectionString = $"{this.configuration[EdgeHubConstants.ConfigKey.IotHubConnectionString]};ModuleId=$edgeHub"; IotHubConnectionStringBuilder iotHubConnectionStringBuilder = IotHubConnectionStringBuilder.Create(edgeHubConnectionString); var topics = new MessageAddressConversionConfiguration(this.inboundTemplates, this.outboundTemplates); builder.RegisterModule(new LoggingModule()); var mqttSettingsConfiguration = new Mock <IConfiguration>(); mqttSettingsConfiguration.Setup(c => c.GetSection(It.IsAny <string>())).Returns(Mock.Of <IConfigurationSection>(s => s.Value == null)); var experimentalFeatures = new ExperimentalFeatures(true, false, false, true); builder.RegisterBuildCallback( c => { // set up loggers for dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("ProtocolGateway")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); var versionInfo = new VersionInfo("v1", "b1", "c1"); var metricsConfig = new MetricsConfig(true, new MetricsListenerConfig()); var backupFolder = Option.None <string>(); string storageFolder = string.Empty; StoreLimits storeLimits = null; if (!int.TryParse(this.configuration["TimeToLiveSecs"], out int timeToLiveSecs)) { timeToLiveSecs = -1; } if (long.TryParse(this.configuration["MaxStorageBytes"], out long maxStorageBytes)) { storeLimits = new StoreLimits(maxStorageBytes); } var storeAndForwardConfiguration = new StoreAndForwardConfiguration(timeToLiveSecs, storeLimits); if (bool.TryParse(this.configuration["UsePersistentStorage"], out bool usePersistentStorage) && usePersistentStorage) { storageFolder = GetOrCreateDirectoryPath(this.configuration["StorageFolder"], EdgeHubConstants.EdgeHubStorageFolder); } if (bool.TryParse(this.configuration["EnableNonPersistentStorageBackup"], out bool enableNonPersistentStorageBackup)) { backupFolder = Option.Some(this.configuration["BackupFolder"]); } var testRoutes = this.routes; string customRoutes = this.configuration["Routes"]; if (!string.IsNullOrWhiteSpace(customRoutes)) { testRoutes = JsonConvert.DeserializeObject <IDictionary <string, string> >(customRoutes); } builder.RegisterModule( new CommonModule( string.Empty, iotHubConnectionStringBuilder.HostName, iotHubConnectionStringBuilder.DeviceId, iotHubConnectionStringBuilder.ModuleId, string.Empty, Option.None <string>(), AuthenticationMode.CloudAndScope, Option.Some(edgeHubConnectionString), false, usePersistentStorage, storageFolder, Option.None <string>(), Option.None <string>(), TimeSpan.FromHours(1), false, this.trustBundle, string.Empty, metricsConfig, enableNonPersistentStorageBackup, backupFolder, Option.None <ulong>(), Option.None <StorageLogLevel>())); builder.RegisterModule( new RoutingModule( iotHubConnectionStringBuilder.HostName, iotHubConnectionStringBuilder.DeviceId, iotHubConnectionStringBuilder.ModuleId, Option.Some(edgeHubConnectionString), testRoutes, true, storeAndForwardConfiguration, ConnectionPoolSize, false, versionInfo, Option.Some(UpstreamProtocol.Amqp), TimeSpan.FromSeconds(5), 101, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(3600), true, TimeSpan.FromSeconds(20), false, Option.None <TimeSpan>(), Option.None <TimeSpan>(), false, 10, 10, false, TimeSpan.FromHours(1), experimentalFeatures)); builder.RegisterModule(new HttpModule()); builder.RegisterModule(new MqttModule(mqttSettingsConfiguration.Object, topics, this.serverCertificate, false, false, false, this.sslProtocols)); builder.RegisterModule(new AmqpModule("amqps", 5671, this.serverCertificate, iotHubConnectionStringBuilder.HostName, true, this.sslProtocols)); }
async Task StartProtocolHead() { const int ConnectionPoolSize = 10; string certificateValue = await SecretsHelper.GetSecret("IotHubMqttHeadCert"); byte[] cert = Convert.FromBase64String(certificateValue); var certificate = new X509Certificate2(cert); string edgeDeviceConnectionString = await SecretsHelper.GetSecretFromConfigKey("edgeCapableDeviceConnStrKey"); // TODO - After IoTHub supports MQTT, remove this and move to using MQTT for upstream connections await ConnectToIotHub(edgeDeviceConnectionString); string edgeHubConnectionString = $"{edgeDeviceConnectionString};ModuleId=$edgeHub"; Client.IotHubConnectionStringBuilder iotHubConnectionStringBuilder = Client.IotHubConnectionStringBuilder.Create(edgeHubConnectionString); var topics = new MessageAddressConversionConfiguration(this.inboundTemplates, this.outboundTemplates); var builder = new ContainerBuilder(); builder.RegisterModule(new LoggingModule()); var mqttSettingsConfiguration = new Mock <IConfiguration>(); mqttSettingsConfiguration.Setup(c => c.GetSection(It.IsAny <string>())).Returns(Mock.Of <IConfigurationSection>(s => s.Value == null)); builder.RegisterBuildCallback( c => { // set up loggers for dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("ProtocolGateway")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); var versionInfo = new VersionInfo("v1", "b1", "c1"); var storeAndForwardConfiguration = new StoreAndForwardConfiguration(-1); builder.RegisterModule(new CommonModule(string.Empty, iotHubConnectionStringBuilder.HostName, iotHubConnectionStringBuilder.DeviceId)); builder.RegisterModule( new RoutingModule( iotHubConnectionStringBuilder.HostName, iotHubConnectionStringBuilder.DeviceId, iotHubConnectionStringBuilder.ModuleId, Option.Some(edgeHubConnectionString), this.routes, false, false, storeAndForwardConfiguration, string.Empty, ConnectionPoolSize, false, versionInfo, Option.Some(UpstreamProtocol.Amqp), true, TimeSpan.FromSeconds(5), 101, false, Option.None <string>(), Option.None <string>()) ); builder.RegisterModule(new HttpModule()); builder.RegisterModule(new MqttModule(mqttSettingsConfiguration.Object, topics, certificate, false, false, string.Empty, false)); builder.RegisterModule(new AmqpModule("amqps", 5671, certificate, iotHubConnectionStringBuilder.HostName)); this.container = builder.Build(); IConfigSource configSource = await this.container.Resolve <Task <IConfigSource> >(); ConfigUpdater configUpdater = await this.container.Resolve <Task <ConfigUpdater> >(); await configUpdater.Init(configSource); ILogger logger = this.container.Resolve <ILoggerFactory>().CreateLogger("EdgeHub"); MqttProtocolHead mqttProtocolHead = await this.container.Resolve <Task <MqttProtocolHead> >(); AmqpProtocolHead amqpProtocolHead = await this.container.Resolve <Task <AmqpProtocolHead> >(); this.protocolHead = new EdgeHubProtocolHead(new List <IProtocolHead> { mqttProtocolHead, amqpProtocolHead }, logger); await this.protocolHead.StartAsync(); }
IContainer BuildContainer(IServiceCollection services) { int connectionPoolSize = this.Configuration.GetValue <int>("IotHubConnectionPoolSize"); bool optimizeForPerformance = this.Configuration.GetValue("OptimizeForPerformance", true); var topics = new MessageAddressConversionConfiguration( this.Configuration.GetSection(Constants.TopicNameConversionSectionName + ":InboundTemplates").Get <List <string> >(), this.Configuration.GetSection(Constants.TopicNameConversionSectionName + ":OutboundTemplates").Get <Dictionary <string, string> >()); string configSource = this.Configuration.GetValue <string>("configSource"); bool useTwinConfig = !string.IsNullOrWhiteSpace(configSource) && configSource.Equals("twin", StringComparison.OrdinalIgnoreCase); var routes = this.Configuration.GetSection("routes").Get <Dictionary <string, string> >(); (bool isEnabled, bool usePersistentStorage, StoreAndForwardConfiguration config, string storagePath)storeAndForward = this.GetStoreAndForwardConfiguration(); IConfiguration mqttSettingsConfiguration = this.Configuration.GetSection("appSettings"); Option <UpstreamProtocol> upstreamProtocolOption = Enum.TryParse(this.Configuration.GetValue("UpstreamProtocol", string.Empty), false, out UpstreamProtocol upstreamProtocol) ? Option.Some(upstreamProtocol) : Option.None <UpstreamProtocol>(); int connectivityCheckFrequencySecs = this.Configuration.GetValue("ConnectivityCheckFrequencySecs", 300); TimeSpan connectivityCheckFrequency = connectivityCheckFrequencySecs < 0 ? TimeSpan.MaxValue : TimeSpan.FromSeconds(connectivityCheckFrequencySecs); // TODO: We don't want to make enabling Cert Auth configurable right now. Turn off Cert auth. //bool clientCertAuthEnabled = this.Configuration.GetValue("ClientCertAuthEnabled", false); bool clientCertAuthEnabled = false; bool cacheTokens = this.Configuration.GetValue("CacheTokens", false); Option <string> workloadUri = this.GetConfigurationValueIfExists <string>(Constants.WorkloadUriVariableName); Option <string> moduleGenerationId = this.GetConfigurationValueIfExists <string>(Constants.ModuleGenerationIdVariableName); string caChainPath = this.Configuration.GetValue("EdgeModuleHubServerCAChainCertificateFile", string.Empty); // n Clients + 1 Edgehub int maxConnectedClients = this.Configuration.GetValue("MaxConnectedClients", 100) + 1; IConfiguration amqpSettings = this.Configuration.GetSection("amqp"); var builder = new ContainerBuilder(); builder.Populate(services); builder.RegisterModule(new LoggingModule()); builder.RegisterBuildCallback( c => { // set up loggers for dotnetty var loggerFactory = c.Resolve <ILoggerFactory>(); InternalLoggerFactory.DefaultFactory = loggerFactory; var eventListener = new LoggerEventListener(loggerFactory.CreateLogger("ProtocolGateway")); eventListener.EnableEvents(CommonEventSource.Log, EventLevel.Informational); }); string productInfo = VersionInfo.Get(Constants.VersionInfoFileName).ToString(); Metrics.BuildMetricsCollector(this.Configuration); // Register modules builder.RegisterModule( new CommonModule( productInfo, this.iotHubHostname, this.edgeDeviceId)); builder.RegisterModule( new RoutingModule( this.iotHubHostname, this.edgeDeviceId, this.edgeModuleId, this.connectionString, routes, storeAndForward.isEnabled, storeAndForward.usePersistentStorage, storeAndForward.config, storeAndForward.storagePath, connectionPoolSize, useTwinConfig, this.VersionInfo, upstreamProtocolOption, optimizeForPerformance, connectivityCheckFrequency, maxConnectedClients, cacheTokens, workloadUri, moduleGenerationId)); builder.RegisterModule(new MqttModule(mqttSettingsConfiguration, topics, ServerCertificateCache.X509Certificate, storeAndForward.isEnabled, clientCertAuthEnabled, caChainPath, optimizeForPerformance)); builder.RegisterModule(new AmqpModule(amqpSettings["scheme"], amqpSettings.GetValue <ushort>("port"), ServerCertificateCache.X509Certificate, this.iotHubHostname)); builder.RegisterModule(new HttpModule()); builder.RegisterInstance <IStartup>(this); IContainer container = builder.Build(); return(container); }