feat(outbox): lab5 run outbox background publisher in api server

This commit is contained in:
Голиков Maximillian Антон
2026-11-09 09:12:48 +03:00
parent af9e94080e
commit 872406773f
2 changed files with 87 additions and 0 deletions
+15
View File
@@ -13,11 +13,13 @@ import (
"syscall"
"time"
"high-loud-apps-labs/internal/broker"
"high-loud-apps-labs/internal/config"
"high-loud-apps-labs/internal/domain"
"high-loud-apps-labs/internal/httpapi"
"high-loud-apps-labs/internal/httpapi/handler"
"high-loud-apps-labs/internal/httpapi/middleware"
"high-loud-apps-labs/internal/outbox"
"high-loud-apps-labs/internal/service"
"high-loud-apps-labs/internal/storage/postgres"
redisstore "high-loud-apps-labs/internal/storage/redis"
@@ -55,6 +57,17 @@ func main() {
store := postgres.New(pool)
rabbitPub, err := broker.NewRabbitPublisher(cfg.RabbitMQURL)
if err != nil {
log.Fatalf("rabbitmq: %v", err)
}
defer rabbitPub.Close()
outboxPub := outbox.NewPublisher(store.Outbox(), rabbitPub, 50)
outboxCtx, outboxCancel := context.WithCancel(context.Background())
defer outboxCancel()
go outboxPub.Run(outboxCtx, cfg.OutboxInterval)
sessionRepo, cachePing, closeSession := newSessionRepo(cfg, store)
defer closeSession()
@@ -145,6 +158,8 @@ func main() {
log.Printf("Получен сигнал завершения; readiness выключен, drain %s", cfg.ShutdownDrain)
ready.Store(false)
outboxCancel()
reconcilerCancel()
if cfg.ShutdownDrain > 0 {