change:本地调试不做幂等

This commit is contained in:
李鹏军 2024-04-01 18:16:50 +08:00
parent 232d7d8254
commit 7331076e44

View File

@ -24,6 +24,12 @@ public class CapFilter : SubscribeFilter
if (context.DeliverMessage.Headers["cap-msg-name"]!.EndsWith(GlobalConst.TrackRefreshSubscribe)) if (context.DeliverMessage.Headers["cap-msg-name"]!.EndsWith(GlobalConst.TrackRefreshSubscribe))
return Task.CompletedTask; return Task.CompletedTask;
// 本地调试不做幂等
if (System.Diagnostics.Debugger.IsAttached)
{
return Task.CompletedTask;
}
var argumentJsonStr = context.Arguments.ToJson(); var argumentJsonStr = context.Arguments.ToJson();
context.DeliverMessage.Headers["sjzy-arguments"] = argumentJsonStr; context.DeliverMessage.Headers["sjzy-arguments"] = argumentJsonStr;
@ -33,8 +39,8 @@ public class CapFilter : SubscribeFilter
using (RedisHelper.Client.Lock("Filter:" + hash, 10)) using (RedisHelper.Client.Lock("Filter:" + hash, 10))
{ {
var isSkip = !string.IsNullOrEmpty(RedisHelper.Client.Get($"CapExcuteFilter:{hash}")); var isSkip = !string.IsNullOrEmpty(RedisHelper.Client.Get($"CapExcuteFilter:{hash}"));
// if (isSkip) if (isSkip)
// throw new BusinessException(ErrorCode, $"检测到重复消费,消费参数:{argumentJsonStr}"); throw new BusinessException(ErrorCode, $"检测到重复消费,消费参数:{argumentJsonStr}");
RedisHelper.Client.Set($"CapExcuteFilter:{hash}", 60 * 10, RedisHelper.Client.Set($"CapExcuteFilter:{hash}", 60 * 10,
TimeSpan.FromHours(1).Seconds); // 1h内不允许一模一样的参数重复消费 TimeSpan.FromHours(1).Seconds); // 1h内不允许一模一样的参数重复消费