Skip to content

Commit

Permalink
Merge pull request #51 from liuyts/master
Browse files Browse the repository at this point in the history
Add a push function for custom message key
  • Loading branch information
kevwan authored Jul 24, 2024
2 parents 5af862f + 2b3c4c2 commit f2ee5c0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kq/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ func (p *Pusher) KPush(ctx context.Context, k, v string) error {

// Push sends a message to the Kafka topic.
func (p *Pusher) Push(ctx context.Context, v string) error {
return p.PushWithKey(ctx, strconv.FormatInt(time.Now().UnixNano(), 10), v)
}

// PushWithKey sends a message with the given key to the Kafka topic.
func (p *Pusher) PushWithKey(ctx context.Context, key, v string) error {
msg := kafka.Message{
Key: []byte(strconv.FormatInt(time.Now().UnixNano(), 10)), // current timestamp
Key: []byte(key),
Value: []byte(v),
}

Expand Down

0 comments on commit f2ee5c0

Please sign in to comment.