From fda9ab3a33e97f6791fadfa2de7febcfe6d515e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=9B=B7?= <284428564@QQ.com> Date: Fri, 9 Aug 2024 14:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handlers/KafkaSubscribe.cs | 46 +++++++++---------- .../Handlers/WanJiaAnProcess.cs | 2 - 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/TelpoPush.WanJiaAn.Worker/Handlers/KafkaSubscribe.cs b/TelpoPush.WanJiaAn.Worker/Handlers/KafkaSubscribe.cs index 9ea96c0..8eccc28 100644 --- a/TelpoPush.WanJiaAn.Worker/Handlers/KafkaSubscribe.cs +++ b/TelpoPush.WanJiaAn.Worker/Handlers/KafkaSubscribe.cs @@ -26,36 +26,36 @@ namespace TelpoPush.WanJiaAn.Worker.Handlers { #if DEBUG //_logger.LogInformation("11312"); - var temp = new Headers(); - string topic = "topic.wanjiaan.push.telpo"; - temp.Add(new Header("DataType", new byte[] { 0, 0, 0, 0 })); - temp.Add(new Header("AlarmType", new byte[] { 2, 0, 0, 0 })); - string json1 = "{\"msg_id\":\"33090000000023391723109173034\",\"device_id\":\"3309000000002339\",\"type\":\"DEVICE_REPORT\",\"device_type\":\"XZL-Q42\",\"event_time\":\"1723109173\",\"app_id\":6755,\"user_id\":\"tel1000\",\"data\":{\"alarm_event\":{\"event_id\":\"17231091733309000000002339\",\"event_start\":\"1723109173\",\"event_type\":2,\"report_type\":1}}}"; - await _WanJiaAnProcess.SendWanJiaAn(json1, topic, temp); + //var temp = new Headers(); + //string topic = "topic.wanjiaan.push.telpo"; + //temp.Add(new Header("DataType", new byte[] { 0, 0, 0, 0 })); + //temp.Add(new Header("AlarmType", new byte[] { 2, 0, 0, 0 })); + //string json1 = "{\"msg_id\":\"33090000000023391723109173034\",\"device_id\":\"3309000000002339\",\"type\":\"DEVICE_REPORT\",\"device_type\":\"XZL-Q42\",\"event_time\":\"1723109173\",\"app_id\":6755,\"user_id\":\"tel1000\",\"data\":{\"alarm_event\":{\"event_id\":\"17231091733309000000002339\",\"event_start\":\"1723109173\",\"event_type\":2,\"report_type\":1}}}"; + //await _WanJiaAnProcess.SendWanJiaAn(json1, topic, temp); - string json2 = "{\"msg_id\":\"33090000000023391723109197082\",\"device_id\":\"3309000000002339\",\"type\":\"DEVICE_REPORT\",\"device_type\":\"XZL-Q42\",\"event_time\":\"1723109197\",\"app_id\":6755,\"user_id\":\"tel1000\",\"data\":{\"alarm_event\":{\"event_end\":\"1723109197\",\"event_id\":\"17231091733309000000002339\",\"event_start\":\"1723109173\",\"event_type\":2,\"report_type\":2}}}"; - await _WanJiaAnProcess.SendWanJiaAn(json2, topic, temp); + //string json2 = "{\"msg_id\":\"33090000000023391723109197082\",\"device_id\":\"3309000000002339\",\"type\":\"DEVICE_REPORT\",\"device_type\":\"XZL-Q42\",\"event_time\":\"1723109197\",\"app_id\":6755,\"user_id\":\"tel1000\",\"data\":{\"alarm_event\":{\"event_end\":\"1723109197\",\"event_id\":\"17231091733309000000002339\",\"event_start\":\"1723109173\",\"event_type\":2,\"report_type\":2}}}"; + //await _WanJiaAnProcess.SendWanJiaAn(json2, topic, temp); - string json3 = "{\"msg_id\":\"33090000000023391723109197036\",\"device_id\":\"3309000000002339\",\"type\":\"DEVICE_REPORT\",\"device_type\":\"XZL-Q42\",\"event_time\":\"1723109197\",\"app_id\":6755,\"user_id\":\"tel1000\",\"data\":{\"alarm_event\":{\"event_end\":\"1723109197\",\"event_id\":\"17231091733309000000002339\",\"event_start\":\"1723109173\",\"event_type\":2,\"image\":\"http://s-cn-xiaoz-1304525121.cos.ap-guangzhou.myqcloud.com/cloud_ts%2F7_3309000000002339%2F3309000000002339_1723109174_p37.jpeg?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdtlQq8bpIWdZH4PBD1xe4Qgon9IXLLrB%26q-sign-time%3D1723109175%3B3446823150%26q-key-time%3D1723109175%3B3446823150%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D708db58b15fdcaceb8bf6eeded5e2664b015cb6c\",\"report_type\":3,\"url\":\"http://s-cn-xiaoz-1304525121.cos.ap-guangzhou.myqcloud.com/cloud_ts%2F7_3309000000002339%2F1723046400_1723109171_1723109175.ts?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdtlQq8bpIWdZH4PBD1xe4Qgon9IXLLrB%26q-sign-time%3D1723109176%3B3446823152%26q-key-time%3D1723109176%3B3446823152%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D2fad04c97bfd9113491eada7d221cc5caab57e5b\",\"video_end\":\"1723109175\",\"video_start\":\"1723109171\"}}}"; - await _WanJiaAnProcess.SendWanJiaAn(json3, topic, temp); + //string json3 = "{\"msg_id\":\"33090000000023391723109197036\",\"device_id\":\"3309000000002339\",\"type\":\"DEVICE_REPORT\",\"device_type\":\"XZL-Q42\",\"event_time\":\"1723109197\",\"app_id\":6755,\"user_id\":\"tel1000\",\"data\":{\"alarm_event\":{\"event_end\":\"1723109197\",\"event_id\":\"17231091733309000000002339\",\"event_start\":\"1723109173\",\"event_type\":2,\"image\":\"http://s-cn-xiaoz-1304525121.cos.ap-guangzhou.myqcloud.com/cloud_ts%2F7_3309000000002339%2F3309000000002339_1723109174_p37.jpeg?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdtlQq8bpIWdZH4PBD1xe4Qgon9IXLLrB%26q-sign-time%3D1723109175%3B3446823150%26q-key-time%3D1723109175%3B3446823150%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D708db58b15fdcaceb8bf6eeded5e2664b015cb6c\",\"report_type\":3,\"url\":\"http://s-cn-xiaoz-1304525121.cos.ap-guangzhou.myqcloud.com/cloud_ts%2F7_3309000000002339%2F1723046400_1723109171_1723109175.ts?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdtlQq8bpIWdZH4PBD1xe4Qgon9IXLLrB%26q-sign-time%3D1723109176%3B3446823152%26q-key-time%3D1723109176%3B3446823152%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D2fad04c97bfd9113491eada7d221cc5caab57e5b\",\"video_end\":\"1723109175\",\"video_start\":\"1723109171\"}}}"; + //await _WanJiaAnProcess.SendWanJiaAn(json3, topic, temp); // await _kafkaService.SubscribeAsync(DoReceive, CancellationToken.None); #else - //LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(5); - //TaskFactory factory = new TaskFactory(lcts); - //try - //{ - // await factory.StartNew(async () => - // { - // await _kafkaService.SubscribeAsync(DoReceive, CancellationToken.None); - // }); - //} - //catch (Exception ex) - //{ - // _logger.LogError($"Subscribe 处理Kafka数据发生异常 {ex.Message}|{ex.Source}|{ex.StackTrace}"); - //} + LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(5); + TaskFactory factory = new TaskFactory(lcts); + try + { + await factory.StartNew(async () => + { + await _kafkaService.SubscribeAsync(DoReceive, CancellationToken.None); + }); + } + catch (Exception ex) + { + _logger.LogError($"Subscribe 处理Kafka数据发生异常 {ex.Message}|{ex.Source}|{ex.StackTrace}"); + } #endif } async void DoReceive(string topic, string message, Headers headers) diff --git a/TelpoPush.WanJiaAn.Worker/Handlers/WanJiaAnProcess.cs b/TelpoPush.WanJiaAn.Worker/Handlers/WanJiaAnProcess.cs index bfc2ffb..abde851 100644 --- a/TelpoPush.WanJiaAn.Worker/Handlers/WanJiaAnProcess.cs +++ b/TelpoPush.WanJiaAn.Worker/Handlers/WanJiaAnProcess.cs @@ -257,8 +257,6 @@ namespace TelpoPush.WanJiaAn.Worker.Handlers { if (model.data != null) { - _logger.LogInformation($"{JsonConvert.SerializeObject(model)}"); - var alarmEvent = JsonConvert.DeserializeObject(model.data.ToString()); if (alarmEvent?.alarm_event != null) {