feat(server): outbox relay 改为 LISTEN/NOTIFY + 30s 兜底轮询

- EventBus::publish() 持久化后执行 NOTIFY outbox_channel
- outbox relay 使用 sqlx::PgListener 监听 + tokio::select! 竞争
- 30s 兜底轮询防止 NOTIFY 丢失,断线自动重连
- 轮询间隔从 5s 提升到 30s,事件延迟降至 <100ms
This commit is contained in:
iven
2026-04-27 17:50:38 +08:00
parent 8d55d98f4f
commit d31d7beb1f
5 changed files with 79 additions and 10 deletions

View File

@@ -406,8 +406,8 @@ async fn main() -> anyhow::Result<()> {
erp_plugin::notification::start_notification_listener(db.clone(), event_bus.clone());
tracing::info!("Plugin notification listener started");
// Start outbox relay (re-publish pending domain events)
outbox::start_outbox_relay(db.clone(), event_bus.clone());
// Start outbox relay (LISTEN/NOTIFY + fallback poll for pending domain events)
outbox::start_outbox_relay(db.clone(), event_bus.clone(), config.database.url.clone());
tracing::info!("Outbox relay started");
// Start timeout checker (scan overdue tasks every 60s)