Skip to content

Commit f2ee5c0

Browse files
authored
Merge pull request #51 from liuyts/master
Add a push function for custom message key
2 parents 5af862f + 2b3c4c2 commit f2ee5c0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kq/pusher.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,13 @@ func (p *Pusher) KPush(ctx context.Context, k, v string) error {
112112

113113
// Push sends a message to the Kafka topic.
114114
func (p *Pusher) Push(ctx context.Context, v string) error {
115+
return p.PushWithKey(ctx, strconv.FormatInt(time.Now().UnixNano(), 10), v)
116+
}
117+
118+
// PushWithKey sends a message with the given key to the Kafka topic.
119+
func (p *Pusher) PushWithKey(ctx context.Context, key, v string) error {
115120
msg := kafka.Message{
116-
Key: []byte(strconv.FormatInt(time.Now().UnixNano(), 10)), // current timestamp
121+
Key: []byte(key),
117122
Value: []byte(v),
118123
}
119124

0 commit comments

Comments
 (0)