using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using RestartService.Alarm;
|
using System;
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
|
namespace RestartService.Monitor
|
{
|
public class EmqxClientMonitor
|
{
|
private static int DeviceCacheExCount = 0;
|
|
public static void monitor()
|
{
|
new Thread(new ThreadStart(() =>
|
{
|
while (true)
|
{
|
try
|
{
|
var result = HttpHp.Get<ResponseData<List<JObject>>>(ConfigurationManager.AppSettings["EmqClientUrl"]);
|
|
if (result.code != 0)
|
{
|
throw new Exception("EMQX服务响应异常");
|
}
|
|
if (result.data.Count == 0)
|
{
|
throw new Exception("MQTT重连失败,服务不可用!");
|
}
|
DeviceCacheExCount = 0;
|
}
|
catch (Exception exc)
|
{
|
DeviceCacheExCount++;
|
if (DeviceCacheExCount > 2 && DeviceCacheExCount % 3 == 0)
|
{
|
try
|
{
|
AlarmHp.ApplicationAlarm("SupportCtrlOldUdpGate", "warn-system", exc.StackTrace, "157.175.231.123", "国外-透传服务" + exc.Message);
|
}
|
catch (Exception ex)
|
{
|
LogHp.WriteLog("透传服务异常", JsonConvert.SerializeObject(ex));
|
}
|
|
}
|
}
|
Thread.Sleep(1000 * 10);
|
}
|
}))
|
{ IsBackground = true }.Start();
|
|
|
}
|
}
|
}
|