Exemple #1
0
 public MQTTDaegunSubscribe(ILoggerFactory loggerFactory, IBackgroundMongoTaskQueue taskQueue, MqttSubscribeConfig mqtt_config)
 {
     mqttOptions = mqtt_config;
     queue       = taskQueue;
     _logger     = loggerFactory.CreateLogger <MQTTDaegunSubscribe>();
     StartSubscribe();
 }
        public MongoBackgroundHostService(IBackgroundMongoTaskQueue taskQueue,
                                          IRedisConnectionFactory redis_factory,
                                          MongoClient mongoclient, MqttSubscribeConfig mqttConfig,
                                          ILoggerFactory loggerFactory)
        {
            TaskQueue = taskQueue;
            _client   = mongoclient;

            _redisFactory = redis_factory;
            _mqttConfig   = mqttConfig;
            _redisDb      = _redisFactory.Connection().GetDatabase();


            _logger = loggerFactory.CreateLogger <MongoBackgroundHostService>();
        }
 public MongoBackgroundHostService(
     IBackgroundMongoTaskQueue taskQueue,
     IConfiguration configuration,
     MqttSubscribeConfig mqttConfig,
     ILoggerFactory loggerFactory,
     MysqlDataAccess da
     )
 {
     TaskQueue       = taskQueue;
     _mqttConfig     = mqttConfig;
     insertBatchList = new ConcurrentBag <DaegunPacketClass>();
     _da             = da;
     BatchInterval   = configuration.GetSection("BatchInterval").Get <TimeSpan>();
     _logger         = loggerFactory.CreateLogger <MongoBackgroundHostService>();
 }
Exemple #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

#if ENABLE_MQTT_BROKER
            var mqttServerOptions = new MqttServerOptionsBuilder()
                                    .WithoutDefaultEndpoint()
                                    .Build();

            services
            .AddHostedMqttServer(mqttServerOptions)
            .AddMqttConnectionHandler()
            .AddConnections();
#endif
            MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient(Configuration.GetConnectionString("mongodb"));

            var redisConfiguration = Configuration.GetSection("redis").Get <RedisConfiguration>();
            var mqttOptions        = Configuration.GetSection("MQTT").Get <MqttSubscribeConfig>();
            services.AddSingleton(mqttOptions);
            services.AddSingleton(redisConfiguration);
            services.AddSingleton <IRedisConnectionFactory, RedisConnectionFactory>();
            services.AddSingleton(client);
            queue_service = new MongoBackgroundTaskQueue(client);
            services.AddSingleton(queue_service);
            //IServiceCollection cols  = services.AddSingleton<IBackgroundMongoTaskQueue, MongoBackgroundTaskQueue>();
            //services.AddHostedService<MongoBackgroundHostService>();



            //byte[] file_array = File.ReadAllBytes("output.txt");

            //byte[] new_fileArray = new byte[file_array.Length + 8];
            //Array.Copy(file_array, new_fileArray, file_array.Length);
            //DaegunPacket packet = PacketParser.ByteToStruct<DaegunPacket>(new_fileArray);
            //packet.timestamp = DateTime.Now;
            //queue_service.QueueBackgroundWorkItem(packet);



            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
 public MQTTBackgroundSubscribeService(ILoggerFactory loggerFactory, IBackgroundMongoTaskQueue taskQueue, MqttSubscribeConfig mqtt_config)
 {
     mqttOptions = mqtt_config;
     queue       = taskQueue;
     logger      = loggerFactory.CreateLogger <MQTTBackgroundSubscribeService>();
 }