feat: Add RabbitMQ message queue integration for profile event publishing in carrier-connector

- Add github.com/rabbitmq/amqp091-go v1.11.0 dependency to go.mod
- Add messageQueue parameter to OrderProfileHandlerWithRepo and DeleteProfileHandlerWithRepo
- Add PublishProfileEvent calls for profile.downloaded and profile.deleted events with goroutines
- Add message queue initialization in main.go with RABBITMQ_URL environment variable
- Add profile-events queue declaration with error handling and fallback
- Add messageQueue parameter to setupRoutes
This commit is contained in:
nutcas3
2026-04-25 06:50:13 +03:00
parent 0ea496b627
commit 6b2a38b51b
5 changed files with 52 additions and 7 deletions
+22 -1
View File
@@ -10,6 +10,7 @@ import (
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/config"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
handler "github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/handler"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/mq"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/webhook"
"github.com/rs/zerolog"
@@ -62,7 +63,27 @@ func main() {
webhookAPIKey := handler.GetEnv("API_SERVER_WEBHOOK_API_KEY", "")
webhookClient := webhook.NewWebhookClient(webhookURL, webhookAPIKey)
setupRoutes(router, client, profileRepo, webhookClient)
// Initialize message queue for async events (optional)
var messageQueue *mq.MessageQueue
rabbitmqURL := handler.GetEnv("RABBITMQ_URL", "")
if rabbitmqURL != "" {
mq, err := mq.NewMessageQueue(rabbitmqURL)
if err != nil {
handler.Logger.Warn().Err(err).Msg("Failed to connect to RabbitMQ, continuing without message queue")
} else {
// Declare profile events queue
if err := mq.DeclareQueue("profile-events"); err != nil {
handler.Logger.Warn().Err(err).Msg("Failed to declare profile-events queue")
mq.Close()
} else {
messageQueue = mq
handler.Logger.Info().Msg("Message queue initialized")
defer messageQueue.Close()
}
}
}
setupRoutes(router, client, profileRepo, webhookClient, messageQueue)
handler.Logger.Info().Str("port", port).Msg("Carrier Connector API server starting")
if err := router.Run(":" + port); err != nil {