Skip to content

Commit a24545c

Browse files
committed
Chore: logging before produce
1 parent 1106266 commit a24545c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

internal/queue/kafka/operator.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package kafkaqueue
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"github.com/IBM/sarama"
78
"github.com/violetpay-org/event-queue/queue"
89
"log"
10+
"sync/atomic"
911
)
1012

13+
var count = &atomic.Int64{}
14+
1115
type ConsumeOperator[Msg any] struct {
1216
serializer queue.MessageSerializer[*sarama.ConsumerMessage, Msg]
1317
callback queue.Callback[Msg]
@@ -304,16 +308,31 @@ func (k *BytesProduceOperator) Produce(message []byte) error {
304308
return errors.New("message is nil")
305309
}
306310

307-
log.Print("Before Produce Message:" + string(k.topic))
311+
var test testStruct
312+
err := json.Unmarshal(message, &test)
313+
if err != nil {
314+
return err
315+
}
308316

309-
_, _, err := producer.SendMessage(&sarama.ProducerMessage{
317+
if test.status == "success" {
318+
count.Add(1)
319+
}
320+
321+
_, _, err = producer.SendMessage(&sarama.ProducerMessage{
310322
Topic: k.topic,
311323
Value: sarama.ByteEncoder(message),
312324
})
313325

326+
log.Print("Produced. BeforeProduce Count (썩세스만): ", count.Load())
327+
314328
if err != nil {
315329
return err
316330
}
317331

318332
return nil
319333
}
334+
335+
type testStruct struct {
336+
requestId string
337+
status string
338+
}

0 commit comments

Comments
 (0)