Files
msgexchange-v2/src/main/kotlin/com/gzzn/omms/msgexchange/ingress/InboxService.kt
T

28 lines
1.0 KiB
Kotlin
Raw Normal View History

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