示例#1
0
        public static void Main(string[] args)
        {
            string qos        = args[0];
            string topic_root = args[1];
            string client_id  = args[2];
            int    maxNumber  = Int32.Parse(args[3]);

            // Console.WriteLine("{0} starting", client_id);
            MqttQos Qos = ParseQos(qos);

            using (var numbersPersistence = new NumbersPersistence(client_id + ".sqlite3"))
            {
                using (var clientPersistence = new SqlitePersistence(numbersPersistence.conn))
                // using (var p = new InMemoryPersistence())
                {
                    var client = new MqttClient(numbersPersistence, clientPersistence, topic_root, client_id, Qos, maxNumber);
                    while (!client.Finished)
                    {
                        try
                        {
                            client.Run();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("{0} : {1}", client_id, ex.ToString());
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(1));
                    }
                }
            }

            Console.WriteLine("{0} done", client_id);
        }
示例#2
0
        public MqttClient(NumbersPersistence numbersPersistence, IMqttPersistence clientPersistence, string topicRoot, string clientId, MqttQos qos, int maxNumber)
        {
            this.clientPersistence  = clientPersistence;
            this.numbersPersistence = numbersPersistence;

            ClientId         = clientId;
            TopicToPublish   = topicRoot + "/" + clientId;
            TopicToSubscribe = topicRoot + "/#";
            Qos = qos;

            this.maxNumber = maxNumber;
            this.previousPublishedNumber = numbersPersistence.GetLastNumberSent();
        }