Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c382b62

Browse files
committed
Code_Updated_Version_1.0.2
1 parent 94b5b29 commit c382b62

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

consumer-services/consumer/consumer.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func ConsumeQueue() error {
6262
// Process incoming messages
6363
for msg := range msgs {
6464
productID := string(msg.Body)
65-
log.Printf("Received product_id: %s")
65+
log.Info("Received product_id:", productID)
6666
i, err := strconv.Atoi(productID)
6767
if err != nil {
6868
log.Fatal(err)
@@ -76,7 +76,7 @@ func ConsumeQueue() error {
7676
}
7777

7878
func processImages(productID int) error {
79-
log.Info("Found::", productID)
79+
log.Info("ProductID:", productID)
8080
collection := datab.ConnectToMongoDB().Collection("product-service-db")
8181
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
8282
defer cancel()
@@ -93,15 +93,21 @@ func processImages(productID int) error {
9393
}
9494
replacement := bson.M{
9595
"product_id": productID,
96+
"product_name": resp.ProductName,
97+
"product_description": resp.ProductDescription,
98+
"product_images": resp.ProductImages,
99+
"product_price": resp.ProductPrice,
96100
"compressed_product_images": resp.CompressedProductImages,
101+
"created_at": time.Now(),
102+
"updated_at": time.Now(),
97103
}
98104
// replaceone ::
99105
result, err := collection.ReplaceOne(ctx, filter, replacement)
100106
if err != nil {
101107
log.Info("Error Found", err)
102108
}
103109
if result.MatchedCount == 1 {
104-
log.Info("Replace Sucessfully::")
110+
log.Info("Compressed Image Path Updated")
105111
} else {
106112
log.Info("Not Replaced::")
107113
return err
@@ -120,13 +126,7 @@ func saveImageLocally(image string) error {
120126
}
121127
defer resp.Body.Close()
122128

123-
if resp.StatusCode != http.StatusOK {
124-
log.Info("HTTP request failed with status: %s\n", resp.Status)
125-
return nil
126-
}
127-
128129
fileName := filepath.Base(imageURL)
129-
130130
err = os.MkdirAll(localDirectory, os.ModePerm)
131131
if err != nil {
132132
log.Info("Failed to create local directory:", err)
@@ -146,7 +146,6 @@ func saveImageLocally(image string) error {
146146
log.Info("Failed to save image to the local file:", err)
147147
return nil
148148
}
149-
150-
log.Info("Image downloaded and saved as %s in directory %s\n", fileName, localDirectory)
149+
log.Info("Path:", localDirectory+imageURL)
151150
return nil
152151
}

0 commit comments

Comments
 (0)