添加日志
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using CommonEntity;
|
||||
using CSRedis;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BLWLogProduce.Models
|
||||
@@ -7,7 +10,9 @@ namespace BLWLogProduce.Models
|
||||
public class MyPublishRedis
|
||||
{
|
||||
public static CSRedisClient? redis4;
|
||||
public static CSRedisClient? redis6;
|
||||
|
||||
public static Logger logger = LogManager.GetCurrentClassLogger();
|
||||
private const string ip = "127.0.0.1";
|
||||
private const string port = "6379";
|
||||
static MyPublishRedis()
|
||||
@@ -16,28 +21,30 @@ namespace BLWLogProduce.Models
|
||||
if (!string.IsNullOrEmpty(redisHostStr))
|
||||
{
|
||||
redis4 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=4");
|
||||
string channel = "__keyevent@4__:expired";
|
||||
redis6 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=6");
|
||||
string channel = "__keyevent@6__:expired";
|
||||
var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
|
||||
{
|
||||
string data = msg.Body;
|
||||
try
|
||||
{
|
||||
var o = JsonSerializer.Deserialize<OnOffLineData>(msg.Body);
|
||||
o.CurrentStatus = "off";
|
||||
string str = Newtonsoft.Json.JsonConvert.SerializeObject(o);
|
||||
var data_take =redis4.Get(data);
|
||||
if (!string.IsNullOrEmpty(data_take))
|
||||
{
|
||||
var o = JsonConvert.DeserializeObject<OnOffLineData>(data_take);
|
||||
o.CurrentStatus = "off";
|
||||
string str = Newtonsoft.Json.JsonConvert.SerializeObject(o);
|
||||
|
||||
redis4.Publish("redis-on_off_line", str);
|
||||
redis6.Publish("redis-on_off_line", str);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("定阅出错:"+data);
|
||||
}
|
||||
});
|
||||
redis4.Subscribe(QQQ);
|
||||
redis6.Subscribe(QQQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MyPublishRedis2
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,6 +548,10 @@ namespace BLWLogProduce.Services
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (poo.cmd_word.Equals("0E")&&poo.fault_list.Count==0&&poo.device_list.Count==0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string TopicKey1 = KafkaKey.BLWLog4NodeJs_RCU_Action_Topic;
|
||||
string DetailKey1 = poo.frame_id.ToString();
|
||||
|
||||
@@ -662,6 +666,7 @@ namespace BLWLogProduce.Services
|
||||
try
|
||||
{
|
||||
|
||||
MyPublishRedis.redis6.Set("ChangLiang", "1", 3600); //设置过期时间1小时,离线事件靠过期事件触发
|
||||
string body = args.Body;
|
||||
CommonEntity.OnOffLineData? usa = System.Text.Json.JsonSerializer.Deserialize<CommonEntity.OnOffLineData>(body);
|
||||
|
||||
@@ -677,6 +682,7 @@ namespace BLWLogProduce.Services
|
||||
logger.Error("RCUOnOffLine:" + body);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
string Key1 = KafkaKey.BLWLog4NodeJs_RCU_OnOffLine_Topic;
|
||||
string Key2 = usa.HostNumber;
|
||||
@@ -790,9 +796,26 @@ namespace BLWLogProduce.Services
|
||||
{
|
||||
string body = args.Body;
|
||||
NewVersionHexData? usa = System.Text.Json.JsonSerializer.Deserialize<NewVersionHexData>(body);
|
||||
byte[] bytes = MyMessagePacker.FastSerialize(usa);
|
||||
string TopicKey = KafkaKey.BLWLog_RCU_Topic;
|
||||
string DetailKey = KafkaKey.RCUNewVersion_RestartReason;
|
||||
|
||||
RestartIOTData rrr = new RestartIOTData()
|
||||
{
|
||||
HotelCode = usa.HotelCode,
|
||||
HostNumber = usa.HostNumber,
|
||||
MAC = usa.MAC,
|
||||
RoomNumber = usa.RoomNumber,
|
||||
EndPoint = usa.RemoteEndPoint,
|
||||
CurrentStatus = usa.CurrentStatus,
|
||||
CurrentTime = usa.CurrentTime,
|
||||
UnixTime = Tools.GetUnixTime_MS(),
|
||||
LauncherVersion= usa.LauncherVersion,
|
||||
RebootReason= usa.RebootReason
|
||||
};
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(rrr));
|
||||
|
||||
//byte[] bytes = MyMessagePacker.FastSerialize(rrr);
|
||||
string TopicKey = KafkaKey.BLWLog4NodeJs_RCU_OnOffLine_Topic;
|
||||
string DetailKey = usa.HotelCode;
|
||||
var dr = await p.ProduceAsync(TopicKey, new Message<string, byte[]> { Key = DetailKey, Value = bytes });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -956,6 +979,7 @@ namespace BLWLogProduce.Services
|
||||
//新版本日志
|
||||
CSRedisCacheHelper.redis3.Subscribe(TSLog_DingYue);
|
||||
CSRedisCacheHelper.redis3.Subscribe(TSLog_DingYue_0X36);
|
||||
CSRedisCacheHelper.redis3.Subscribe(DingYue11);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user