コード例 #1
0
        static void Main(string[] args)
        {
            AppSetting appconfig = new AppSetting("appsettings.json");

            AbsMqttBase.SetDefaultLoggerName("nlog.config", true);
            string          mysql_connectionString = appconfig.GetConnectionString("peiudb");
            ISessionFactory sessionFactory         = CreateSessionFactory(mysql_connectionString, appconfig.GetAssembly());
            var             redisConfiguration     = appconfig.GetSection <RedisConfiguration>("redis");

            ConnectionMultiplexer conn = ConnectionMultiplexer.Connect(redisConfiguration.ConfigurationOptions);

            // NLog: setup the logger first to catch all errors
            NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("nlog.config");
            Console.CancelKeyPress       += Console_CancelKeyPress;
            EventSubscribeWorker worker = new EventSubscribeWorker(sessionFactory, conn);

            CancellationToken token = cancellationTokenSource.Token;

            worker.Initialize();
            while (true)
            {
                try
                {
                    token.ThrowIfCancellationRequested();
                    Task workTask = worker.MqttSubscribeAsync(token);
                    workTask.Wait();
                    Task.Delay(100);
                }
                catch (Exception ex)
                {
                }
            }
        }