mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-19 02:05:14 +00:00
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:
@@ -10,12 +10,13 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
|
||||
"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"
|
||||
)
|
||||
|
||||
// OrderProfileHandlerWithRepo orders a profile via ES2+ and persists it in the repo.
|
||||
func OrderProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient) gin.HandlerFunc {
|
||||
func OrderProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient, messageQueue *mq.MessageQueue) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var order ProfileOrder
|
||||
if err := c.ShouldBindJSON(&order); err != nil {
|
||||
@@ -78,6 +79,15 @@ func OrderProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileR
|
||||
})
|
||||
}
|
||||
|
||||
// Publish message queue event for profile download
|
||||
if messageQueue != nil {
|
||||
go messageQueue.PublishProfileEvent("profile.downloaded", order.ICCID, map[string]any{
|
||||
"imsi": order.IMSI,
|
||||
"profileType": order.ProfileType,
|
||||
"status": downloadResp.ExecutionStatus,
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"profile": &ProfileResponse{
|
||||
@@ -170,7 +180,7 @@ func ListProfilesHandlerWithRepo(repo repository.ProfileRepository) gin.HandlerF
|
||||
}
|
||||
|
||||
// DeleteProfileHandlerWithRepo deletes a profile from the SM-DP+ and marks it deleted in the repo.
|
||||
func DeleteProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient) gin.HandlerFunc {
|
||||
func DeleteProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient, messageQueue *mq.MessageQueue) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
profileID := c.Param("profileId")
|
||||
if profileID == "" {
|
||||
@@ -197,6 +207,14 @@ func DeleteProfileHandlerWithRepo(client *es2.ES2Client, repo repository.Profile
|
||||
})
|
||||
}
|
||||
|
||||
// Publish message queue event for profile deletion
|
||||
if messageQueue != nil {
|
||||
go messageQueue.PublishProfileEvent("profile.deleted", profileID, map[string]any{
|
||||
"executionStatus": deleteResp.ExecutionStatus,
|
||||
"statusMessage": deleteResp.StatusMessage,
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "Profile deletion requested",
|
||||
|
||||
Reference in New Issue
Block a user