public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider provider) { var mqtt = new MqttConfig(); this.Configuration.GetSection("Mqtt").Bind(mqtt); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseGrpcMetrics(); provider.MapInternalMqttTopic <CommandConsumer>(mqtt.InternalBroker.CommandTopic); app.UseEndpoints(endpoints => { endpoints.MapGrpcService <IngressRouter>(); endpoints.MapGrpcService <EgressRouter>(); endpoints.MapControllers(); if (env.IsDevelopment()) { endpoints.MapGrpcReflectionService(); } }); }
public static Guid ConnectTLS() { string passphrase = ConfigurationManager.AppSettings["passphrase"]; string caCertificate = ConfigurationManager.AppSettings["caCertificate"]; string clientCertificate = ConfigurationManager.AppSettings["clientCertificate"]; string privateKey = ConfigurationManager.AppSettings["privateKey"]; MqttConfig config = new MqttConfig { ClientCerificatePassphrase = passphrase, SSLConnection = true, Port = 8884, CAcertificate = caCertificate, ClientCertificate = clientCertificate, PrivateKey = privateKey }; MqttStatus status = MQTTLib.MqttClient.Connect("test.mosquitto.org", config); if (!status.Error) { Console.WriteLine("Connected!"); } else { Console.WriteLine($"Error:{status.ErrorMessage}"); } return(status.Key); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMqttServer mqttServer) { app.UseCors(o => o .AllowCredentials() .AllowAnyMethod() .AllowAnyHeader() .AllowAnyOrigin()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); MqttConfig mqttConfig = new MqttConfig(mqttServer, app.ApplicationServices.GetService <IMqttClientMain>()); mqttConfig.Config(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public static void AddMqttBrokers(this IServiceCollection services, IConfiguration configuration) { var id = configuration.GetValue <string>("ApplicationId"); var mqtt = new MqttConfig(); configuration.GetSection("Mqtt").Bind(mqtt); var privatemqtt = mqtt.InternalBroker; var publicmqtt = mqtt.PublicBroker; services.AddInternalMqttService(options => { options.Ssl = privatemqtt.Ssl; options.Host = privatemqtt.Host; options.Port = privatemqtt.Port; options.Username = privatemqtt.Username; options.Password = privatemqtt.Password; options.Id = $"router-{id}"; }); services.AddMqttService(options => { options.Ssl = publicmqtt.Ssl; options.Host = publicmqtt.Host; options.Port = publicmqtt.Port; options.Username = publicmqtt.Username; options.Password = publicmqtt.Password; options.Id = $"router-{id}-{Guid.NewGuid():N}"; }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider provider) { var mqtt = new MqttConfig(); this.m_configuration.GetSection("Mqtt").Bind(mqtt); app.UseForwardedHeaders(); app.UseRouting(); app.UseCors(p => { p.SetIsOriginAllowed(host => true) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); app.UseSwagger(c => { c.RouteTemplate = "network/swagger/{documentName}/swagger.json"; c.PreSerializeFilters.Add((swagger, httpReq) => { swagger.Servers = new List <OpenApiServer> { new OpenApiServer { Url = $"http://{httpReq.Host.Value}" }, new OpenApiServer { Url = $"https://{httpReq.Host.Value}" } }; }); }); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/network/swagger/v1/swagger.json", "Sensate Network API v1"); c.RoutePrefix = "network/swagger"; }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(p => { p.SetIsOriginAllowed(host => true) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); app.UseMiddleware <ErrorLoggingMiddleware>(); app.UseMiddleware <ApiKeyValidationMiddleware>(); app.UseMiddleware <RequestLoggingMiddleware>(); app.UseMiddleware <JsonErrorHandlerMiddleware>(); provider.MapInternalMqttTopic <CommandConsumer>(mqtt.InternalBroker.CommandTopic); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public ServicesConfig() { MqttConfig = new MqttConfig(); IoTConfig = new IoTConfig(); DiscoveryConfig = new DiscoveryConfig(); ScriptEngineConfig = new ScriptEngineConfig(); PluginsConfig = new PluginsConfig(); }
public static async Task RunAsync() { //MqttNetConsoleLogger.ForwardToConsole(); // iot.eclipse.org await ExecuteTestAsync("iot.eclipse.org TCP", new MqttClientOptionsBuilder().WithTcpServer("iot.eclipse.org", 1883).Build()); await ExecuteTestAsync("iot.eclipse.org WS", new MqttClientOptionsBuilder().WithWebSocketServer("iot.eclipse.org:80/mqtt").Build()); await ExecuteTestAsync("iot.eclipse.org WS TLS", new MqttClientOptionsBuilder().WithWebSocketServer("iot.eclipse.org:443/mqtt").WithTls().Build()); // test.mosquitto.org await ExecuteTestAsync("test.mosquitto.org TCP", new MqttClientOptionsBuilder().WithTcpServer("test.mosquitto.org", 1883).Build()); await ExecuteTestAsync("test.mosquitto.org TCP TLS", new MqttClientOptionsBuilder().WithTcpServer("test.mosquitto.org", 8883).WithTls().Build()); await ExecuteTestAsync("test.mosquitto.org WS", new MqttClientOptionsBuilder().WithWebSocketServer("test.mosquitto.org:8080/mqtt").Build()); await ExecuteTestAsync("test.mosquitto.org WS TLS", new MqttClientOptionsBuilder().WithWebSocketServer("test.mosquitto.org:8081/mqtt").WithTls().Build()); // broker.hivemq.com await ExecuteTestAsync("broker.hivemq.com TCP", new MqttClientOptionsBuilder().WithTcpServer("broker.hivemq.com", 1883).Build()); await ExecuteTestAsync("broker.hivemq.com WS", new MqttClientOptionsBuilder().WithWebSocketServer("broker.hivemq.com:8000/mqtt").Build()); // mqtt.swifitch.cz await ExecuteTestAsync("mqtt.swifitch.cz", new MqttClientOptionsBuilder().WithTcpServer("mqtt.swifitch.cz", 1883).Build()); // CloudMQTT var configFile = Path.Combine("E:\\CloudMqttTestConfig.json"); if (File.Exists(configFile)) { var config = MqttConfig.Parse(File.ReadAllText(configFile)); await ExecuteTestAsync("CloudMQTT TCP", new MqttClientOptionsBuilder().WithTcpServer(config.Server, config.Port).WithCredentials(config.Username, config.Password).Build()); await ExecuteTestAsync("CloudMQTT TCP TLS", new MqttClientOptionsBuilder().WithTcpServer(config.Server, config.SslPort).WithCredentials(config.Username, config.Password).WithTls().Build()); await ExecuteTestAsync("CloudMQTT WS TLS", new MqttClientOptionsBuilder().WithWebSocketServer(config.Server + ":" + config.SslWebSocketPort + "/mqtt").WithCredentials(config.Username, config.Password).WithTls().Build()); } Write("Finished.", ConsoleColor.White); Console.ReadLine(); }
public void Configure(IServiceProvider provider) { var @public = new MqttConfig(); this.Configuration.GetSection("Mqtt").Bind(@public); provider.MapMqttTopic <MqttMeasurementHandler>(@public.MeasurementTopic); provider.MapMqttTopic <MqttMessageHandler>(@public.MessageTopic); }
public void Configure(IServiceProvider provider) { var mqtt = new MqttConfig(); this.Configuration.GetSection("Mqtt").Bind(mqtt); var @private = mqtt.InternalBroker; provider.MapInternalMqttTopic <MqttBulkNumberTriggerHandler>(@private.BulkMeasurementTopic); provider.MapInternalMqttTopic <MqttRegexTriggerHandler>(@private.BulkMessageTopic); provider.MapInternalMqttTopic <CommandConsumer>(@private.CommandTopic); }
public MqttService(IHostApplicationLifetime appLifetime, IOptions <MqttConfig> mqttConfig, ILogger <MqttService> logger) { var mqttFactory = new MqttFactory(); _mqttClient = mqttFactory.CreateMqttClient(); _mqttConfig = mqttConfig.Value; _logger = logger; _appLifetime = appLifetime; }
public void Configure(IServiceProvider provider) { var mqtt = new MqttConfig(); this.Configuration.GetSection("Mqtt").Bind(mqtt); var @private = mqtt.InternalBroker; provider.MapInternalMqttTopic <MqttBulkMeasurementHandler>(@private.BulkMeasurementTopic); provider.MapInternalMqttTopic <MqttBulkMessageHandler>(@private.BulkMessageTopic); provider.MapInternalMqttTopic <MqttNetworkEventConsumer>(@private.NetworkEventQueueTopic); provider.MapInternalMqttTopic <MqttTriggerEventConsumer>(@private.TriggerEventQueueTopic); }
public GenericMqttClient(MqttConfig config, IChannel channel, IMqttDispatch dispatcher = null) { this.dispatcher = dispatcher ?? new GenericMqttDispatcher(); session = new MqttSession(config); session.OnConnect += Session_OnConnect; session.OnDisconnect += Session_OnDisconnect; session.OnRetry += Session_OnRetry; this.channel = channel; this.channel.OnReceive += Channel_OnReceive; this.channel.OnClose += Channel_OnClose; this.channel.OnError += Channel_OnError; this.channel.OnStateChange += Channel_OnStateChange; }
public override void Arrange() { base.Arrange(); _mqtt = new MqttNetController(); _config = new MqttConfig { Broker = "broker.hivemq.com", Port = 1883, ClientID = "D3vS1m-MSTests-Client" }; _mqtt.Connected += OnConnected; _mqtt.CreateClient(_config); }
private static MqttClientProxyCollection TryInitializeMqtt(MqttConfig config) { MqttClientProxyCollection result = new MqttClientProxyCollection(); foreach (MqttAddress addr in config.DataBrokerAddress) { IMqttClient client = CreateMqttClient(addr); if (client != null) { result.Add(new MqttClientProxy(client, addr)); } } return(result); }
public ModbusBackgroundService(ILoggerFactory loggerFactory, IModbusFactory modbus_factory, MqttClientProxyCollection mqttClientProxies, IRedisConnectionFactory redisFactory, IConfiguration configuration, ModbusSystem modbusSystem) { logger = loggerFactory.CreateLogger <ModbusBackgroundService>(); config = configuration; modbusFactory = modbus_factory; mqtt_clients = mqttClientProxies; mqtt_config = configuration.GetSection("MQTTBrokers").Get <MqttConfig>(); SiteId = configuration.GetSection("SiteId").Get <int>(); DeviceIndex = configuration.GetSection("DeviceIndex").Get <int>(); modbus = modbusSystem; redis = redisFactory.Connection().GetDatabase(1); }
public NeonConfig() { Database = new DatabaseConfig(); Scripts = new ScriptConfig(); Mqtt = new MqttConfig(); Plugins = new PluginConfig(); Tasks = new TaskConfig(); FileSystem = new FileSystemConfig(); Components = new ComponentConfig(); EventsDatabase = new EventDatabaseConfig(); IoT = new IoTConfig(); JwtToken = "password"; AutoLoadComponents = true; Home = new HomeConfig(); }
public GenericMqttClient(MqttConfig config, IChannel channel, IMqttDispatch dispatcher = null) { this.dispatcher = dispatcher != null ? dispatcher : new GenericMqttDispatcher(); timeoutMilliseconds = config.MaxTransmitSpan.TotalMilliseconds; session = new MqttSession(config); session.OnConnect += Session_OnConnect; session.OnDisconnect += Session_OnDisconnect; session.OnRetry += Session_OnRetry; this.channel = channel; this.channel.OnReceive += Channel_OnReceive; this.channel.OnClose += Channel_OnClose; this.channel.OnError += Channel_OnError; this.channel.OnStateChange += Channel_OnStateChange; }
public PVBackgroundService(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, IModbusFactory modbus_factory, MqttClientProxyCollection mqttClientProxies, IRedisConnectionFactory redisFactory, IConfiguration configuration) { logger = loggerFactory.CreateLogger <PVBackgroundService>(); config = configuration; mqtt_clients = mqttClientProxies; mqtt_config = configuration.GetSection("MQTTBrokers").Get <MqttConfig>(); SiteId = configuration.GetSection("SiteId").Get <int>(); string mssql_conn = configuration.GetConnectionString("mssql"); redis = redisFactory.Connection().GetDatabase(1); DeviceName = configuration.GetSection("Modbus:DeviceName").Get <string>(); DeviceName = DeviceName.Substring(0, DeviceName.Length - 1); sessionFactory = new MsSqlAccessManager().CreateSessionFactory(mssql_conn); }
public static Guid Connect(MqttConfig config) { string url = ConfigurationManager.AppSettings["url"]; MqttStatus status = MQTTLib.MqttClient.Connect(url, config); if (!status.Error) { Console.WriteLine("Connected!"); } else { Console.WriteLine($"Error:{status.ErrorMessage}"); } return(status.Key); }
public PiraeusMqttClient(MqttConfig config, IChannel channel, IMqttDispatch dispatcher = null) { this.dispatcher = dispatcher ?? new GenericMqttDispatcher(); timeoutMilliseconds = config.MaxTransmitSpan.TotalMilliseconds; session = new MqttSession(config); session.OnKeepAlive += Session_OnKeepAlive; session.OnConnect += Session_OnConnect; session.OnDisconnect += Session_OnDisconnect; session.OnRetry += Session_OnRetry; Channel = channel; Channel.OnReceive += Channel_OnReceive; Channel.OnClose += Channel_OnClose; Channel.OnError += Channel_OnError; Channel.OnStateChange += Channel_OnStateChange; queue = new Queue <byte[]>(); }
private async Task <MqttClientProxyCollection> TryInitializeMqtt(MqttConfig config) { MqttClientProxyCollection result = new MqttClientProxyCollection(); IMqttClient peiu_client = await CreateMqttClient(config.PEIUEventBrokerAddress); result.PeiuEventBrokerProxy = new MqttClientProxy(peiu_client, config.PEIUEventBrokerAddress); foreach (MqttAddress addr in config.DataBrokerAddress) { IMqttClient client = await CreateMqttClient(addr); if (client != null) { result.Add(new MqttClientProxy(client, addr)); } } return(result); }
private static async Task <IManagedMqttClient> InitMqtt(MqttConfig cfg) { var optionBuilder = new MqttClientOptionsBuilder() .WithClientId($"shome.scene.processor-{Guid.NewGuid()}") .WithTcpServer(cfg.Host, cfg.Port); if (!string.IsNullOrWhiteSpace(cfg.User)) { optionBuilder = optionBuilder.WithCredentials(cfg.User, cfg.Password); } var options = new ManagedMqttClientOptionsBuilder() .WithAutoReconnectDelay(TimeSpan.FromSeconds(5)) .WithClientOptions(optionBuilder.Build()) .Build(); var mqttClient = new MqttFactory().CreateManagedMqttClient(); //await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("#").WithAtLeastOnceQoS().Build()); mqttClient.Connected += (sender, args) => { _logger.LogInformation("mqtt connected"); }; mqttClient.ConnectingFailed += (sender, args) => { _logger.LogError($"mqtt connection fail. Error {args.Exception}"); }; mqttClient.Disconnected += (sender, args) => { _logger.LogWarning($"mqtt disconnected. Error {args.Exception}"); }; mqttClient.SynchronizingSubscriptionsFailed += (sender, args) => { _logger.LogError($"mqtt sync subscriptions fail. Error {args.Exception}"); }; mqttClient.ApplicationMessageReceived += MqttClientOnApplicationMessageReceived; await mqttClient.StartAsync(options); return(mqttClient); }
public PVBackgroundService(NLog.ILogger loggerFactory, MqttClientProxyCollection mqttClientProxies, RedisConnectionFactory redisFactory, IConfiguration configuration) { logger = loggerFactory; config = configuration; mqtt_clients = mqttClientProxies; mqtt_config = configuration.GetSection("MQTTBrokers").Get <MqttConfig>(); SiteId = configuration.GetSection("SiteId").Get <int>(); string mssql_conn = configuration.GetConnectionString("mssql"); string etri_conn = configuration.GetConnectionString("etridb"); PollInterval = configuration.GetSection("PollInterval").Get <TimeSpan>(); redis = redisFactory.Connection().GetDatabase(1); DeviceName = configuration.GetSection("DeviceName").Get <string>(); redisDeviceName = configuration.GetSection("RedisKeyName").Get <string>(); sessionFactory = new MsSqlAccessManager().CreateSessionFactory(mssql_conn); mysqlSessionFactory = new MySqlAccessManager(etri_conn, Assembly.GetExecutingAssembly()).SessionFactory; }
public MqttProtocolAdapter(PiraeusConfig config, IAuthenticator authenticator, IChannel channel, ILogger logger, HttpContext context = null) { this.config = config; this.logger = logger; MqttConfig mqttConfig = new MqttConfig(config.KeepAliveSeconds, config.AckTimeoutSeconds, config.AckRandomFactor, config.MaxRetransmit, config.MaxLatencySeconds, authenticator, config.ClientIdentityNameClaimType, config.GetClientIndexes()); this.context = context; session = new MqttSession(mqttConfig); InitializeAuditor(config); Channel = channel; Channel.OnClose += Channel_OnClose; Channel.OnError += Channel_OnError; Channel.OnStateChange += Channel_OnStateChange; Channel.OnReceive += Channel_OnReceive; Channel.OnOpen += Channel_OnOpen; }
public void ConfigureServices(IServiceCollection services) { var mqtt = new MqttConfig(); var db = new DatabaseConfig(); this.Configuration.GetSection("Mqtt").Bind(mqtt); this.Configuration.GetSection("Database").Bind(db); var privatemqtt = mqtt.InternalBroker; services.AddDocumentStore(db.MongoDB.ConnectionString, db.MongoDB.DatabaseName, db.MongoDB.MaxConnections); services.AddScoped <IMeasurementRepository, MeasurementRepository>(); services.AddScoped <ISensorStatisticsRepository, SensorStatisticsRepository>(); services.AddScoped <IMessageRepository, MessageRepository>(); services.Configure <MetricsOptions>(this.Configuration.GetSection("HttpServer:Metrics")); services.AddHostedService <MetricsService>(); services.AddInternalMqttService(options => { options.Ssl = privatemqtt.Ssl; options.Host = privatemqtt.Host; options.Port = privatemqtt.Port; options.Username = privatemqtt.Username; options.Password = privatemqtt.Password; options.Id = Guid.NewGuid().ToString(); options.TopicShare = "$share/sensateiot-storage/"; }); services.AddLogging(builder => { builder.AddConfiguration(this.Configuration.GetSection("Logging")); if (IsDevelopment()) { builder.AddDebug(); } builder.AddConsole(); }); services.AddMqttHandlers(); }
static void Main(string[] args) { try { MqttConfig config = Common.CommonConnection.GetConfig(); //Guid key = Common.CommonConnection.ConnectTLS(); //config.CleanSession = false; //config.ClientId = "MyTest"; config.AllowWildcardsInTopicFilters = true; Guid key = Common.CommonConnection.Connect(config); string topic = ConfigurationManager.AppSettings["topic"]; topic = "/test/hola"; MqttStatus status = MqttClient.Subscribe(key, topic, "SaveMessage", 1); if (status.Error) { throw new Exception(status.ErrorMessage); } Console.WriteLine($"Subscribed to topic:{topic}"); Console.WriteLine($"Press <enter> to exit..."); Console.ReadLine(); MqttClient.Disconnect(key); } catch (Exception ex) { while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } } }
public void ConfigureServices(IServiceCollection services) { var mqtt = new MqttConfig(); var connString = this.Configuration.GetValue <string>("Database:MongoDB:ConnectionString"); var connectionCount = this.Configuration.GetValue <int>("Database:MongoDB:MaxConnections"); var dbName = this.Configuration.GetValue <string>("Database:MongoDB:DatabaseName"); this.Configuration.GetSection("Mqtt").Bind(mqtt); services.AddMongoDb(connString, dbName, connectionCount); services.AddLogging(builder => { builder.AddConfiguration(this.Configuration.GetSection("Logging")); }); services.Configure <GatewaySettings>(this.Configuration.GetSection("Gateway")); services.AddMqttService(options => { options.Ssl = mqtt.Ssl; options.Host = mqtt.Host; options.Port = mqtt.Port; options.Username = mqtt.Username; options.Password = mqtt.Password; options.Id = Guid.NewGuid().ToString(); options.TopicShare = "$share/ingress/"; }); services.AddLogging(builder => { builder.AddConfiguration(this.Configuration.GetSection("Logging")); if (IsDevelopment()) { builder.AddDebug(); } builder.AddConsole(); }); services.AddMqttHandlers(); services.AddHttpClient(); }
public static Guid Connect() { MqttConfig config = GetConfig(); return(Connect(config)); }
public void ConfigureServices(IServiceCollection services) { var db = new DatabaseConfig(); var mqtt = new MqttConfig(); var cache = new CacheConfig(); this.m_configuration.GetSection("Database").Bind(db); this.m_configuration.GetSection("Mqtt").Bind(mqtt); this.m_configuration.GetSection("Cache").Bind(cache); var proxyLevel = this.m_configuration.GetValue <int>("System:ProxyLevel"); var privatemqtt = mqtt.InternalBroker; services.AddDocumentStore(db.MongoDB.ConnectionString, db.MongoDB.DatabaseName, db.MongoDB.MaxConnections); services.AddConnectionStrings(db.Networking.ConnectionString, db.SensateIoT.ConnectionString); services.AddAuthorizationContext(); services.AddNetworkingContext(); services.AddDistributedCaches <PaginationResponse <Sensor> >(cache.Host, cache.Port); services.AddCors(); services.AddInternalMqttService(options => { options.Ssl = privatemqtt.Ssl; options.Host = privatemqtt.Host; options.Port = privatemqtt.Port; options.Username = privatemqtt.Username; options.Password = privatemqtt.Password; options.Id = Guid.NewGuid().ToString(); }); services.Configure <InternalBrokerConfig>(this.m_configuration.GetSection("Mqtt:InternalBroker")); services.Configure <RouterConfig>(this.m_configuration.GetSection("Router")); services.Configure <BlobOptions>(this.m_configuration.GetSection("Storage")); services.Configure <MetricsOptions>(this.m_configuration.GetSection("HttpServer:Metrics")); services.AddScoped <ITriggerAdministrationRepository, TriggerAdministrationRepository>(); services.AddScoped <IMessageRepository, MessageRepository>(); services.AddScoped <IControlMessageRepository, ControlMessageRepository>(); services.AddScoped <IMeasurementRepository, MeasurementRepository>(); services.AddScoped <ISensorRepository, SensorRepository>(); services.AddScoped <ISensorLinkRepository, SensorLinkRepository>(); services.AddScoped <IAccountRepository, AccountRepository>(); services.AddScoped <IApiKeyRepository, ApiKeyRepository>(); services.AddScoped <ILiveDataHandlerRepository, LiveDataHandlerRepository>(); services.AddScoped <ISensorService, SensorService>(); services.AddScoped <ICommandPublisher, CommandPublisher>(); services.AddScoped <IBlobRepository, BlobRepository>(); services.AddScoped <IAuditLogRepository, AuditLogRepository>(); services.AddSingleton <IBlobService, FilesystemBlobService>(); services.AddSingleton <IRouterClient, RouterClient>(); services.AddSingleton <IAuthorizationService, AuthorizationService>(); services.AddSingleton <IMeasurementAuthorizationService, MeasurementAuthorizationService>(); services.AddSingleton <IMessageAuthorizationService, MessageAuthorizationService>(); services.AddSingleton <IHashAlgorithm, SHA256Algorithm>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddHostedService <BatchRoutingService>(); services.AddHostedService <MetricsService>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Sensate IoT Network API - Version 1", Version = "v1" }); c.SchemaFilter <ObjectIdSchemaFilter>(); c.OperationFilter <ObjectIdOperationFilter>(); c.AddSecurityDefinition("X-ApiKey", new OpenApiSecurityScheme { In = ParameterLocation.Header, Name = "X-ApiKey", Type = SecuritySchemeType.ApiKey, Description = "API key needed to access the endpoints." }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Name = "X-ApiKey", Type = SecuritySchemeType.ApiKey, In = ParameterLocation.Header, Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "X-ApiKey" }, }, Array.Empty <string>() } }); }); services.AddReverseProxy(proxyLevel); services.AddRouting(); services.AddControllers().AddNewtonsoftJson(); services.AddMqttHandlers(); }
public MqttNetAdapter(IMqttFactory mqttFactory, IOptions <MqttConfig> mqttConfig) { _mqtt = mqttFactory.CreateMqttClient(); _mqttConfig = mqttConfig.Value; }