feat(msg): 完整实现 msg 消息服务

包含 channels/preferences/templates/grpc/kafka/outbox/push/redis 等完整实现
This commit is contained in:
SpecialX
2026-07-10 19:09:52 +08:00
parent 21530dc7f6
commit 7b7abbb309
51 changed files with 5204 additions and 371 deletions

View File

@@ -0,0 +1,62 @@
/**
* msg 服务 Kafka Topic 映射。
*
* 仲裁依据:
* - M5消费 topic 用 `edu.teaching.*` / `edu.identity.*` / `edu.insight.*`
* - 发布 topic 用 `edu.notification.*`02-architecture-design.md §5.2
*
* PRODUCER_TOPIC_MAPeventType → topicOutboxPublisher 按此路由发布。
* CONSUMER_TOPICSmsg 消费的所有 topic 列表KafkaConsumer 订阅。
*/
/** 生产者eventType → Kafka topic 路由 */
export const PRODUCER_TOPIC_MAP: Record<string, string> = {
"notification.sent": "edu.notification.sent",
"notification.read": "edu.notification.read",
"notification.recalled": "edu.notification.recalled",
"notification.failed": "edu.notification.failed",
};
/** 兜底 topic未在 TOPIC_MAP 命中的 eventType 走此 topic */
export const FALLBACK_TOPIC = "edu.notification.events";
/** 消费者:订阅的 topic 列表iam 6 + core-edu 5 + data-ana 1 = 12 类事件) */
export const CONSUMER_TOPICS: readonly string[] = [
// iamidentity
"edu.identity.user.created",
"edu.identity.user.updated",
"edu.identity.user.deleted",
"edu.identity.user.role_changed",
"edu.identity.role.created",
"edu.identity.role.updated",
// core-eduteaching
"edu.teaching.exam.published",
"edu.teaching.assignment.submitted",
"edu.teaching.assignment.graded",
"edu.teaching.grade.recorded",
"edu.teaching.attendance.recorded",
// data-anainsight
"edu.insight.mastery.updated",
] as const;
/** 消费事件 → 通知类型 映射KafkaConsumer 路由用) */
export const CONSUMER_EVENT_TYPE_MAP: Record<string, string> = {
"edu.identity.user.created": "system",
"edu.identity.user.role_changed": "system",
"edu.identity.role.created": "system",
"edu.identity.role.updated": "system",
"edu.teaching.exam.published": "exam",
"edu.teaching.assignment.submitted": "homework",
"edu.teaching.assignment.graded": "grade",
"edu.teaching.grade.recorded": "grade",
"edu.teaching.attendance.recorded": "attendance",
"edu.insight.mastery.updated": "mastery",
};
/**
* 根据 eventType 解析目标 topic。
* 未命中时降级到 FALLBACK_TOPIC。
*/
export function resolveTopic(eventType: string): string {
return PRODUCER_TOPIC_MAP[eventType] ?? FALLBACK_TOPIC;
}