CZGL.AliIoTClient 裏設置了 7 個委託事件,在程序的不不同生命週期觸發。
1)7個委託事件
/// <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;
使用方法
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;
這裏是舊版本的文檔,可以參考一下。
https://www.cnblogs.com/whuanle/p/10786991.html