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 EmqxPushMonitor
|
{
|
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["EmqPushUrl"]);
|
|
if (result.code != 0)
|
{
|
throw new Exception("响应数据异常");
|
}
|
|
if (result.data.Count == 0)
|
{
|
throw new Exception("响应数据异常");
|
}
|
|
DeviceCacheExCount = 0;
|
}
|
catch (Exception exc)
|
{
|
DeviceCacheExCount++;
|
if (DeviceCacheExCount > 2 && DeviceCacheExCount % 3 == 0)
|
{
|
try
|
{
|
AlarmHp.ApplicationAlarm("PushService_MessageQueue", "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();
|
|
|
}
|
}
|
}
|