diff --git a/BLWLogProduce/Models/MyPublishRedis.cs b/BLWLogProduce/Models/MyPublishRedis.cs index 285227c..7fc36f8 100644 --- a/BLWLogProduce/Models/MyPublishRedis.cs +++ b/BLWLogProduce/Models/MyPublishRedis.cs @@ -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>(channel, (msg) => { + string data = msg.Body; try { - var o = JsonSerializer.Deserialize(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(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 - { - - } } diff --git a/BLWLogProduce/Services/KafkaProduce.cs b/BLWLogProduce/Services/KafkaProduce.cs index 5d0d5fe..3bc4377 100644 --- a/BLWLogProduce/Services/KafkaProduce.cs +++ b/BLWLogProduce/Services/KafkaProduce.cs @@ -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(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(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 { 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) { diff --git a/BLWLogServer/Services/KafkaConsume.cs b/BLWLogServer/Services/KafkaConsume.cs index ca60df7..15cd3ac 100644 --- a/BLWLogServer/Services/KafkaConsume.cs +++ b/BLWLogServer/Services/KafkaConsume.cs @@ -396,19 +396,19 @@ namespace BLWLogServer.Services else if (k.Equals(KafkaKey.RCUNewVersion_RestartReason)) { - var collection = client.GetDatabase("udppackage").GetCollection("rcu_hexdata"); - NewVersionHexData UDPPPP = MyMessagePacker.FastDeserialize(v); - NewVersionHexData_db cv = new NewVersionHexData_db(); - cv.HotelCode = UDPPPP.HotelCode; - cv.HostNumber = UDPPPP.HostNumber; - cv.RoomNumber = UDPPPP.RoomNumber; - cv.CurrentTime = UDPPPP.CurrentTime; - cv.RemoteEndPoint = UDPPPP.RemoteEndPoint; - cv.CmdType = UDPPPP.CmdType; - cv.HexData = UDPPPP.HexData; - cv.CurrentTime = UDPPPP.CurrentTime; + //var collection = client.GetDatabase("udppackage").GetCollection("rcu_hexdata"); + //NewVersionHexData UDPPPP = MyMessagePacker.FastDeserialize(v); + //NewVersionHexData_db cv = new NewVersionHexData_db(); + //cv.HotelCode = UDPPPP.HotelCode; + //cv.HostNumber = UDPPPP.HostNumber; + //cv.RoomNumber = UDPPPP.RoomNumber; + //cv.CurrentTime = UDPPPP.CurrentTime; + //cv.RemoteEndPoint = UDPPPP.RemoteEndPoint; + //cv.CmdType = UDPPPP.CmdType; + //cv.HexData = UDPPPP.HexData; + //cv.CurrentTime = UDPPPP.CurrentTime; - await collection.InsertOneAsync(cv); + //await collection.InsertOneAsync(cv); } else if (k.Equals(KafkaKey.RCUNewVersion_0E)) { @@ -476,9 +476,10 @@ namespace BLWLogServer.Services } } } - catch (OperationCanceledException) + catch (OperationCanceledException ex) { - logger.Error("操作出错"); + logger.Error("操作出错"+ex.Message); + logger.Error(ex.StackTrace); Console.WriteLine("操作错误"); } catch (Exception ex) diff --git a/CommonEntity/Iot.cs b/CommonEntity/Iot.cs index a47e5a5..39b337f 100644 --- a/CommonEntity/Iot.cs +++ b/CommonEntity/Iot.cs @@ -72,6 +72,12 @@ namespace CommonEntity public string? DeviceAddress { get; set; } } + public class RestartIOTData:OnOffLineData + { + public byte[]? LauncherVersion { get; set; } + public byte[]? RebootReason { get; set; } + } + [GenerateSerializer()] [MessagePackObject()] public class OnOffLineData diff --git a/CommonEntity/NewVersionHexData.cs b/CommonEntity/NewVersionHexData.cs index 653efc3..08de32d 100644 --- a/CommonEntity/NewVersionHexData.cs +++ b/CommonEntity/NewVersionHexData.cs @@ -31,6 +31,21 @@ namespace CommonEntity [Key(6)] public DateTime CurrentTime { get; set; } + + [Key(7)] + public string? MAC { get; set; } + + [Key(8)] + public string? CurrentStatus { get; set; } + + [Key(9)] + public long? UnixTime { get; set; } + + [Key(10)] + public byte[]? LauncherVersion { get; set; } + + [Key(11)] + public byte[]? RebootReason { get; set; } } diff --git a/CommonEntity/UDPPackage.cs b/CommonEntity/UDPPackage.cs index fed1f47..8136ea4 100644 --- a/CommonEntity/UDPPackage.cs +++ b/CommonEntity/UDPPackage.cs @@ -35,7 +35,7 @@ namespace CommonEntity /// 心跳包 /// public static string BLWLog4NodeJs_RCU_Topic = "blwlog4Nodejs-rcu-heartbeat-topic"; - public static string BLWLog4NodeJs_RCU_OnOffLine_Topic = "blwlog4Nodejs-rcu-onoffline-topic"; + public static string BLWLog4NodeJs_RCU_OnOffLine_Topic = "blwlog4Nodejs-rcu-onoffline-topic-0"; public static string BLWLog4NodeJs_RCU_Action_Topic = "blwlog4Nodejs-rcu-action-topic"; #endregion diff --git a/CommonTools/CSRedisCacheHelper.cs b/CommonTools/CSRedisCacheHelper.cs index 4f17b19..f058ac6 100644 --- a/CommonTools/CSRedisCacheHelper.cs +++ b/CommonTools/CSRedisCacheHelper.cs @@ -39,34 +39,15 @@ namespace Common string channel = "__keyevent@4__:expired"; var QQQ = new ValueTuple>(channel, (msg) => { - //string Key = CacheKey.UPGradeProgressBar + "_" + id; try { - if (!msg.Body.StartsWith("hb#")) - { - bool containsHyphen = msg.Body.Contains("-"); - bool isNumeric = msg.Body.All(char.IsDigit); - if (containsHyphen == false && isNumeric) - { - //string hotelcode = Tools.HostNumberToHotelCode(msg.Body).ToString(); - //OnOffLineData o = new OnOffLineData(); - //o.HotelCode = hotelcode; - //o.HostNumber = msg.Body; - //o.CurrentStatus = "off"; - //o.CurrentTime = DateTime.Now; - ////新来的数据 - //string str = Newtonsoft.Json.JsonConvert.SerializeObject(o); - //CSRedisCacheHelper.redis3.Publish("redis-on_off_line", str); - //redis4.Set(HeartBeatPrefix + "_" + msg.Body, 1, 5 * 60); - } - } } catch (Exception ex) { } }); - redis.Subscribe(QQQ); + //redis.Subscribe(QQQ); } } /// diff --git a/ConsoleApp2/GoodRedis.cs b/ConsoleApp2/GoodRedis.cs new file mode 100644 index 0000000..0a3bc3f --- /dev/null +++ b/ConsoleApp2/GoodRedis.cs @@ -0,0 +1,40 @@ +using CSRedis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp2 +{ + public class GoodRedis + { + public static CSRedisClient? redis6; + + private const string ip = "127.0.0.1"; + private const string port = "6379"; + static GoodRedis() + { + var redisHostStr = string.Format("{0}:{1}", ip, port); + if (!string.IsNullOrEmpty(redisHostStr)) + { + redis6 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=6"); + //string channel = "__keyevent@6__:expired"; + string channel = "__keyevent@6__:expired"; + var QQQ = new ValueTuple>(channel, (msg) => + { + //body 是键 + string data = msg.Body; + try + { + Console.WriteLine(data); + } + catch (Exception ex) + { + } + }); + redis6.Subscribe(QQQ); + } + } + } +} diff --git a/ConsoleApp2/Program.cs b/ConsoleApp2/Program.cs index 7dcbe90..427eefa 100644 --- a/ConsoleApp2/Program.cs +++ b/ConsoleApp2/Program.cs @@ -5,6 +5,7 @@ using BLWData.Entity; using CommonEntity; using CommonTools; using MessagePack; +using Newtonsoft.Json; namespace ConsoleApp2 { @@ -13,6 +14,10 @@ namespace ConsoleApp2 static void Main(string[] args) { + GoodRedis.redis6.Set("aaa", "bbb", 10); + Console.ReadLine(); + string YYY111111 = File.ReadAllText("2.txt"); + var o = JsonConvert.DeserializeObject(YYY111111); string afds = "hello"; string dda = afds; dda = "world"; @@ -52,7 +57,7 @@ namespace ConsoleApp2 string HOSTNUMBER = "099008" + MAC1 + MAC2; string nnn = File.ReadAllText("1.txt"); - UDPPackage? usa = JsonSerializer.Deserialize(nnn); + UDPPackage? usa = System.Text.Json.JsonSerializer.Deserialize(nnn); AAA a = new AAA(); MyClass mm = new MyClass(); mm.Age = 30; diff --git a/Redis定阅/Program.cs b/Redis定阅/Program.cs index db08978..d9cbd71 100644 --- a/Redis定阅/Program.cs +++ b/Redis定阅/Program.cs @@ -17,6 +17,7 @@ namespace Redis定阅 NengHao? poo = System.Text.Json.JsonSerializer.Deserialize(body); })); CSRedisCacheHelper.redis.Subscribe(DingYue3); + Console.ReadLine(); } } } diff --git a/Redis定阅/bin/Debug/net8.0/CommonEntity.dll b/Redis定阅/bin/Debug/net8.0/CommonEntity.dll index f0ca105..104c7c3 100644 Binary files a/Redis定阅/bin/Debug/net8.0/CommonEntity.dll and b/Redis定阅/bin/Debug/net8.0/CommonEntity.dll differ diff --git a/Redis定阅/bin/Debug/net8.0/CommonEntity.pdb b/Redis定阅/bin/Debug/net8.0/CommonEntity.pdb index ba153dc..a79fe9f 100644 Binary files a/Redis定阅/bin/Debug/net8.0/CommonEntity.pdb and b/Redis定阅/bin/Debug/net8.0/CommonEntity.pdb differ diff --git a/Redis定阅/bin/Debug/net8.0/CommonTools.dll b/Redis定阅/bin/Debug/net8.0/CommonTools.dll index 9e672b1..70b818e 100644 Binary files a/Redis定阅/bin/Debug/net8.0/CommonTools.dll and b/Redis定阅/bin/Debug/net8.0/CommonTools.dll differ diff --git a/Redis定阅/bin/Debug/net8.0/CommonTools.pdb b/Redis定阅/bin/Debug/net8.0/CommonTools.pdb index d8a2bde..e472458 100644 Binary files a/Redis定阅/bin/Debug/net8.0/CommonTools.pdb and b/Redis定阅/bin/Debug/net8.0/CommonTools.pdb differ diff --git a/Redis定阅/bin/Debug/net8.0/Redis定阅.dll b/Redis定阅/bin/Debug/net8.0/Redis定阅.dll index 4d4f475..a6c9a10 100644 Binary files a/Redis定阅/bin/Debug/net8.0/Redis定阅.dll and b/Redis定阅/bin/Debug/net8.0/Redis定阅.dll differ diff --git a/Redis定阅/bin/Debug/net8.0/Redis定阅.exe b/Redis定阅/bin/Debug/net8.0/Redis定阅.exe index 53881e7..28612ae 100644 Binary files a/Redis定阅/bin/Debug/net8.0/Redis定阅.exe and b/Redis定阅/bin/Debug/net8.0/Redis定阅.exe differ diff --git a/Redis定阅/bin/Debug/net8.0/Redis定阅.pdb b/Redis定阅/bin/Debug/net8.0/Redis定阅.pdb index 1676c45..b3900b1 100644 Binary files a/Redis定阅/bin/Debug/net8.0/Redis定阅.pdb and b/Redis定阅/bin/Debug/net8.0/Redis定阅.pdb differ diff --git a/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfo.cs b/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfo.cs index 2a4b16f..1b71aab 100644 --- a/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfo.cs +++ b/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Redis定阅")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+10bf712006c48a55355558d20b38cacc42f7879c")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3de5990573473ba6dad2b9f61b1d597740cd6ff2")] [assembly: System.Reflection.AssemblyProductAttribute("Redis定阅")] [assembly: System.Reflection.AssemblyTitleAttribute("Redis定阅")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfoInputs.cache b/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfoInputs.cache index d4998bb..5e037f9 100644 --- a/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfoInputs.cache +++ b/Redis定阅/obj/Debug/net8.0/Redis定阅.AssemblyInfoInputs.cache @@ -1 +1 @@ -5283559792cfb48abbd55d29822fde595259debf0e2dbd5145d5bb9737d31a98 +cffca3bad22d59989963e58ffa867bb7a20c1d17663478a4cf724d50f06891d2 diff --git a/Redis定阅/obj/Debug/net8.0/Redis定阅.csproj.AssemblyReference.cache b/Redis定阅/obj/Debug/net8.0/Redis定阅.csproj.AssemblyReference.cache index 58cc6cb..d4c3554 100644 Binary files a/Redis定阅/obj/Debug/net8.0/Redis定阅.csproj.AssemblyReference.cache and b/Redis定阅/obj/Debug/net8.0/Redis定阅.csproj.AssemblyReference.cache differ diff --git a/Redis定阅/obj/Debug/net8.0/Redis定阅.dll b/Redis定阅/obj/Debug/net8.0/Redis定阅.dll index 4d4f475..a6c9a10 100644 Binary files a/Redis定阅/obj/Debug/net8.0/Redis定阅.dll and b/Redis定阅/obj/Debug/net8.0/Redis定阅.dll differ diff --git a/Redis定阅/obj/Debug/net8.0/Redis定阅.pdb b/Redis定阅/obj/Debug/net8.0/Redis定阅.pdb index 1676c45..b3900b1 100644 Binary files a/Redis定阅/obj/Debug/net8.0/Redis定阅.pdb and b/Redis定阅/obj/Debug/net8.0/Redis定阅.pdb differ diff --git a/Redis定阅/obj/Debug/net8.0/apphost.exe b/Redis定阅/obj/Debug/net8.0/apphost.exe index 53881e7..28612ae 100644 Binary files a/Redis定阅/obj/Debug/net8.0/apphost.exe and b/Redis定阅/obj/Debug/net8.0/apphost.exe differ diff --git a/Redis定阅/obj/Debug/net8.0/ref/Redis定阅.dll b/Redis定阅/obj/Debug/net8.0/ref/Redis定阅.dll index 64c6f39..b830d6e 100644 Binary files a/Redis定阅/obj/Debug/net8.0/ref/Redis定阅.dll and b/Redis定阅/obj/Debug/net8.0/ref/Redis定阅.dll differ diff --git a/Redis定阅/obj/Debug/net8.0/refint/Redis定阅.dll b/Redis定阅/obj/Debug/net8.0/refint/Redis定阅.dll index 64c6f39..b830d6e 100644 Binary files a/Redis定阅/obj/Debug/net8.0/refint/Redis定阅.dll and b/Redis定阅/obj/Debug/net8.0/refint/Redis定阅.dll differ diff --git a/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfo.cs b/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfo.cs index da98011..5d4bf78 100644 --- a/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfo.cs +++ b/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Redis定阅")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+10bf712006c48a55355558d20b38cacc42f7879c")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3de5990573473ba6dad2b9f61b1d597740cd6ff2")] [assembly: System.Reflection.AssemblyProductAttribute("Redis定阅")] [assembly: System.Reflection.AssemblyTitleAttribute("Redis定阅")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfoInputs.cache b/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfoInputs.cache index 40091ab..a68e257 100644 --- a/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfoInputs.cache +++ b/Redis定阅/obj/Release/net8.0/Redis定阅.AssemblyInfoInputs.cache @@ -1 +1 @@ -99d430bebbce6c50f252c7cf5891f373a780ce938fba0ebed0f195265e8a331a +6b5070cb382d125c9ffb0bb5415855e4173eae9cf2c6bd156d0b4a3335889da7 diff --git a/Redis定阅/obj/Release/net8.0/Redis定阅.csproj.AssemblyReference.cache b/Redis定阅/obj/Release/net8.0/Redis定阅.csproj.AssemblyReference.cache index 935f56c..2f4d906 100644 Binary files a/Redis定阅/obj/Release/net8.0/Redis定阅.csproj.AssemblyReference.cache and b/Redis定阅/obj/Release/net8.0/Redis定阅.csproj.AssemblyReference.cache differ