add cap消费失败预警

This commit is contained in:
李鹏军 2024-03-06 11:47:48 +08:00
parent 3b5a915df8
commit a127285d18

View File

@ -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);
}
};
});
}