Skip to content

Commit d70904e

Browse files
authored
feat: use JSON-encoded value as Kafka message key for easy debugging (#330)
1 parent 0e0416a commit d70904e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

notify.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/rs/zerolog/log"
@@ -49,20 +50,29 @@ func (h *handler) sendNotify(ctx context.Context, mid uint32, userID uint32, sen
4950
return
5051
}
5152

52-
data, err := proto.Marshal(&notifypb.Notify{
53+
msg := &notifypb.Notify{
5354
Mid: mid,
5455
UserId: userID,
5556
FromUserId: senderID,
5657
Type: notifyType,
5758
Title: title,
58-
})
59+
}
60+
61+
data, err := proto.Marshal(msg)
5962
if err != nil {
6063
log.Error().Err(err).Msg("failed to marshal notification")
6164
return
6265
}
6366

67+
key, err := json.Marshal(msg)
68+
if err != nil {
69+
log.Error().Err(err).Msg("failed to marshal notification key")
70+
return
71+
}
72+
6473
err = h.k.WriteMessages(ctx, kafka.Message{
6574
Topic: notifyTopic,
75+
Key: key,
6676
Value: data,
6777
})
6878
if err != nil {

0 commit comments

Comments
 (0)