Beispiel #1
0
        static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            // NLog: setup the logger first to catch all errors
            NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("nlog.config");
            NLog.ILogger           logger            = NLog.LogManager.Configuration.LogFactory.GetLogger("");
            CassandraConfiguration cassandra_config  = config.GetSection("cassandra").Get <CassandraConfiguration>();
            MqttAddress            data_mqtt_address = config.GetSection("MQTTBrokers:DataBrokerAddress").Get <MqttAddress>();

            cancellationTokenSource = new CancellationTokenSource();
            IBackgroundTaskQueue <JObject> dataQueue = new BackgroundTaskQueue <JObject>();

            mqtt_worker                         = new CollectWorker(dataQueue);
            Console.CancelKeyPress             += Console_CancelKeyPress;
            cassandraWorker                     = new BackgroundCassandraWorker(logger, cancellationTokenSource, cassandra_config, dataQueue);
            cassandraWorker.RunWorkerCompleted += CassandraWorker_RunWorkerCompleted;

            Task t = mqtt_worker.ConnectionAsync(data_mqtt_address.ClientId, data_mqtt_address.BindAddress, data_mqtt_address.Port, (ushort)data_mqtt_address.QosLevel, data_mqtt_address.Topic);

            t.Wait();
            Task worker_Task = cassandraWorker.RunWorkerAsync();

            worker_Task.Wait();
        }
Beispiel #2
0
        public MqttFactoryHost(MqttAddress mqttAddress)
        {
            Address = mqttAddress;

            //var ClientOptions = new MqttClientOptions
            //{
            //    ClientId = mqttOptions.ClientId,
            //    ChannelOptions = new MqttClientTcpOptions
            //    {
            //        Server = mqttOptions.BindAddress,
            //        Port = mqttOptions.Port
            //    },

            //};

            client = new MqttFactory().CreateMqttClient()
                     .UseConnectedHandler(HandleConnectedAsync)
                     .UseDisconnectedHandler(HandleDisconnectedAsync)
                     .UseApplicationMessageReceivedHandler(HandleApplicationMessageReceivedEvent);

            Task <MqttClientAuthenticateResult> t = ConnectAsync();

            t.Wait();

            //{
            //    var result = await client.ConnectAsync(ClientOptions);
            //}
            //catch (Exception exception)
            //{
            //    _logger.LogError(exception, "### CONNECTING FAILED ###" + Environment.NewLine + exception);
            //}
        }
 public MqttClientProxy(IMqttClient client, MqttAddress options)
 {
     MqttClient = client;
     Options    = options;
 }