Refactor application initialization to load configuration and enhance message processing. Introduce effective subscription topic handling and improve error management in NATS consumer. Update tests for publisher error handling and add new dependency injection method for app initialization.

This commit is contained in:
windyboy
2025-11-14 22:43:04 +08:00
parent 9cce4610b6
commit 02e54a2670
8 changed files with 196 additions and 35 deletions
+10 -1
View File
@@ -6,6 +6,7 @@ import (
"caatsm/internal/domain"
"context"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"go.uber.org/zap"
@@ -45,7 +46,7 @@ func (r *Repository) InsertOne(ctx context.Context, msg *domain.ParsedMessage) e
ON CONFLICT (uuid) DO NOTHING
`
_, err = r.pool.Exec(ctx, query,
tag, err := r.pool.Exec(ctx, query,
row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8],
row[9], row[10], row[11], row[12], row[13], row[14],
)
@@ -53,6 +54,14 @@ func (r *Repository) InsertOne(ctx context.Context, msg *domain.ParsedMessage) e
return fmt.Errorf("failed to insert message: %w", err)
}
if tag.RowsAffected() == 0 {
r.logger.Info("Duplicate message skipped",
zap.String("uuid", msg.Uuid),
zap.String("message_id", msg.MessageID),
)
return nil
}
r.logger.Debug("Inserted message",
zap.String("uuid", msg.Uuid),
zap.String("message_id", msg.MessageID),