排课计算、课表发布、补考自动编排三类任务统一接入消息系统。
业务任务与 Outbox 消息同一事务落库,避免“数据库成功但消息没发出去”。 RabbitMQ 使用持久化消息、发布确认、手动 ACK、Quorum Queue、死信队列。 增加处理租约、心跳、异常重试、最大重试次数和幂等状态控制。 保留 InMemory 模式,开发环境无需安装 RabbitMQ。 支持多实例竞争消费,后续可以横向扩容。 新增 /health/messaging 消息系统健康检查。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Domain.System;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Exams;
|
||||
using Jiaowu.Api.Infrastructure.Grades;
|
||||
@@ -18,8 +19,7 @@ public sealed class MakeupExamsController(
|
||||
AppDbContext db,
|
||||
ICurrentUserDataScope currentUserDataScope,
|
||||
MakeupExamEligibilityService eligibilityService,
|
||||
MakeupExamArrangementService arrangementService,
|
||||
MakeupExamAutoJobQueue autoJobQueue) : ControllerBase
|
||||
MakeupExamArrangementService arrangementService) : ControllerBase
|
||||
{
|
||||
private const string Managers =
|
||||
SystemRoles.SuperAdmin + "," + SystemRoles.AcademicAdmin;
|
||||
@@ -336,10 +336,12 @@ public sealed class MakeupExamsController(
|
||||
MakeupExamPlanId = planId
|
||||
};
|
||||
db.MakeupExamAutoJobs.Add(job);
|
||||
db.BackgroundJobOutboxMessages.Add(
|
||||
BackgroundJobOutboxMessage.Create(
|
||||
BackgroundJobKind.MakeupExamAuto,
|
||||
job.Id));
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
|
||||
autoJobQueue.Enqueue(job.Id);
|
||||
|
||||
return AcceptedAtAction(nameof(GetAutoJob), new { jobId = job.Id },
|
||||
new { jobId = job.Id, status = job.Status.ToString() });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user