CZGL.AliIoTClient 裏設置了 7 個委託事件,在程序的不不一樣生命週期觸發。html
/// <summary> /// 服務器屬性設置 /// </summary> public PublishPropertyEventHandler PubPropertyEventHandler; /// <summary> /// 服務調用 /// </summary> public PublishServiceEventHandler PubServiceEventHandler; /// <summary> /// 收到其它Topic時觸發 /// </summary> public PublishCommonEventHandler PubCommonEventHandler; /// <summary> /// 當 QOS=1或2時,收到訂閱觸發 /// </summary> public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgPublishedEventHandler PubedEventHandler; /// <summary> /// 向服務器發佈 Topic 時 /// </summary> public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgSubscribedEventHandler SubedEventHandler; /// <summary> /// 向服務器發佈 Topic 失敗時 /// </summary> public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgUnsubscribedEventHandler UnSubedEventHandler; /// <summary> /// 斷開鏈接時 /// </summary> public uPLibrary.Networking.M2Mqtt.MqttClient.ConnectionClosedEventHandler ConnectionClosedEventHandler;
使用方法node
public static void TestEvent(object sender, MqttMsgPublishEventArgs e) { { // handle message received string topic = e.Topic; string message = Encoding.ASCII.GetString(e.Message); Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("get topic message,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("topic: " + topic); Console.WriteLine("get messgae :\n" + message); }
client.PubPropertyEventHandler += TestEvent;
這裏是舊版本的文檔,能夠參考一下。
http://www.javashuo.com/article/p-eswgwngo-e.htmlgit