feat(runtime): U07 生命周期装配 + stub 装配冒烟(ACM2-10 U07/U01 遗留)
- PipelineLifecycle:ServerStartupEvent 后在专用单线程(msgx-pump/msgx-dispatcher,daemon) 拉起 Pump/Dispatcher 循环;停机 requestStop+interrupt+join;@Requires(msgx.pipeline.autostart=true) - PipelineProps.pipeline.autostart(默认 false,生产/测试默认不自动起循环,防泄漏线程) - stub 装配(infra/stub,@Requires(msgx.stubs=true)):7 仓储内存实装 + StubXmlCodec(未实装 → CODEC_ERROR 走 FAILED 可重放路径)+ StubRedis + StubDeliveryPort + Holder Factory - 配置:application-dev.yml(stubs+autostart,/env、/beans 放开,无需 DB 即可 dev 跑通); application-test.yml(stubs=true、autostart=false);README 补 dev stub 运行说明 - PipelineSmokeTest(4):等价 /beans 装配核验 + 收报→主泵领取→FAILED(CODEC_ERROR) + U11 重放 回 PENDING + Dispatcher flush 聚合(stub 用例前清内存状态防上下文复用串扰) - 全量测试 34 个通过
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.gzzn.omms.msgexchange.nextgen
|
||||
|
||||
import com.gzzn.omms.msgexchange.nextgen.delivery.Dispatcher
|
||||
import com.gzzn.omms.msgexchange.nextgen.processing.Pump
|
||||
import io.micronaut.context.annotation.Requires
|
||||
import io.micronaut.runtime.event.annotation.EventListener
|
||||
import io.micronaut.runtime.server.event.ServerStartupEvent
|
||||
import jakarta.annotation.PreDestroy
|
||||
import jakarta.inject.Singleton
|
||||
|
||||
/**
|
||||
* U07(T03+N29):管道生命周期装配——服务启动(ServerStartupEvent)后,在各自专用单线程
|
||||
* (msgx-pump / msgx-dispatcher,不占用 Netty event loop)上拉起 Pump 与 Dispatcher 循环;
|
||||
* 停机时 requestStop + interrupt + join。仅当 `msgx.pipeline.autostart=true` 时装配
|
||||
* (默认关:需要真实仓储或 msgx.stubs=true 才安全开启)。
|
||||
*/
|
||||
@Requires(property = "msgx.pipeline.autostart", value = "true")
|
||||
@Singleton
|
||||
class PipelineLifecycle(
|
||||
private val pump: Pump,
|
||||
private val dispatcher: Dispatcher,
|
||||
) {
|
||||
private val threads = mutableListOf<Thread>()
|
||||
|
||||
@Volatile
|
||||
private var started = false
|
||||
|
||||
@EventListener
|
||||
fun start(event: ServerStartupEvent) {
|
||||
startIfNeeded()
|
||||
}
|
||||
|
||||
private fun startIfNeeded() {
|
||||
if (started) return
|
||||
started = true
|
||||
threads += spawn("msgx-pump", pump::loop)
|
||||
threads += spawn("msgx-dispatcher", dispatcher::loop)
|
||||
}
|
||||
|
||||
private fun spawn(name: String, body: () -> Unit): Thread =
|
||||
Thread.ofPlatform().name(name).daemon(true).start { body() }
|
||||
|
||||
@PreDestroy
|
||||
fun stop() {
|
||||
pump.stop()
|
||||
dispatcher.stop()
|
||||
threads.forEach { it.interrupt() } // 解除 Thread.sleep 阻塞,加速退出
|
||||
threads.forEach { runCatching { it.join(3000) } }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user