2026-09-07 15:11:33 +08:00
|
|
|
package com.gzzn.omms.msgexchange.ingress
|
|
|
|
|
|
|
|
|
|
import com.gzzn.omms.msgexchange.infra.persistence.CminmsgInboxRepository
|
2026-09-10 10:59:58 +08:00
|
|
|
import com.gzzn.omms.msgexchange.infra.persistence.ProcStateRepository
|
2026-09-07 15:11:33 +08:00
|
|
|
import jakarta.inject.Singleton
|
|
|
|
|
import java.time.Instant
|
|
|
|
|
|
2026-09-10 10:59:58 +08:00
|
|
|
/**
|
|
|
|
|
* ACMA-8 流程 1 · compat 写路径:HTTP 落信 + PG 入队(非生产主拓扑;主路径=InboxPoller 轮询)。
|
|
|
|
|
* 两步不在同一事务:信箱成功而 PG 失败时原文不丢失,由轮询按 ID 区间补建(design.md §3.1)。
|
|
|
|
|
*/
|
2026-09-07 15:11:33 +08:00
|
|
|
@Singleton
|
|
|
|
|
class InboxService(
|
|
|
|
|
private val inbox: CminmsgInboxRepository,
|
2026-09-10 10:59:58 +08:00
|
|
|
private val procState: ProcStateRepository,
|
2026-09-07 15:11:33 +08:00
|
|
|
) {
|
|
|
|
|
private val log = org.slf4j.LoggerFactory.getLogger(InboxService::class.java)
|
|
|
|
|
|
2026-09-09 17:53:08 +08:00
|
|
|
data class Receipt(val msgId: Long, val receivedAt: Instant)
|
2026-09-07 15:11:33 +08:00
|
|
|
|
2026-09-10 10:59:58 +08:00
|
|
|
fun accept(rawXml: String, now: Instant = Instant.now()): Receipt {
|
2026-09-07 15:11:33 +08:00
|
|
|
val id = inbox.insertRaw(rawXml)
|
2026-09-10 10:59:58 +08:00
|
|
|
procState.insertIfAbsent(id, now)
|
2026-09-09 17:53:08 +08:00
|
|
|
log.info("compat-accepted msgId={}", id)
|
2026-09-10 10:59:58 +08:00
|
|
|
return Receipt(id, now)
|
2026-09-07 15:11:33 +08:00
|
|
|
}
|
|
|
|
|
}
|