From a127285d18a8608d0406e1780cbca0749af18221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=86=9B?= <2357729423@qq.com> Date: Wed, 6 Mar 2024 11:47:48 +0800 Subject: [PATCH] =?UTF-8?q?add=20cap=E6=B6=88=E8=B4=B9=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=A2=84=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SjzyTrackApplicationModule.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs b/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs index 2bea18a6..ba706085 100644 --- a/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs +++ b/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs @@ -1,7 +1,9 @@ -using DotNetCore.CAP; +using System.Text.Json; +using DotNetCore.CAP; using Microsoft.Extensions.Configuration; using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.Logger; +using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.InterfaceRelay.Application.Contracts; using SJZY.Track.Application.Contract; using SJZY.Track.Application.Localization; @@ -70,7 +72,7 @@ namespace SJZY.Track.Application remoteServiceConfigurationName: "InterfaceForward", asDefaultService: false ); - + //CAP context.Services.AddCapTableNameService(); context.Services.AddCap(options => @@ -87,11 +89,24 @@ namespace SJZY.Track.Application options.FailedRetryCount = 10; options.UseDashboard(dashboardOptions => { - dashboardOptions.PathBase = System.Diagnostics.Debugger.IsAttached ? "" : configuration["Swagger:JsonUrlPrefix"]; + dashboardOptions.PathBase = System.Diagnostics.Debugger.IsAttached + ? "" + : configuration["Swagger:JsonUrlPrefix"]; }); options.FailedThresholdCallback = faileCalback => { - LogHelper.Error($@"{faileCalback.MessageType} 失败了,消息名称: {faileCalback.Message}"); + try + { + LogHelper.Error($@" + |-CAP失败回调事件: + |-处理类型:{(faileCalback.MessageType == DotNetCore.CAP.Messages.MessageType.Subscribe ? "消费消息达到最大重试次数,需要开发人员介入" : "生产消息推送失败")} + |-头部信息:{faileCalback?.Message?.Headers?.ToJson()} + |-消息内容:{((JsonElement)faileCalback?.Message?.Value).GetRawText()}"); + } + catch (Exception ex) + { + LogHelper.Error("【严重】CAP失败回调事件发生未处理异常" + ex); + } }; }); }