Skip to content

Commit

Permalink
feat: get topic name on producer
Browse files Browse the repository at this point in the history
Signed-off-by: Eray Ates <[email protected]>
  • Loading branch information
rytsh committed Jul 15, 2024
1 parent baf159a commit adf8acd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,7 @@ func (c *Client) Skip(modify func(SkipMap) SkipMap) {

c.logger.Debug("wkafka skip modified", "skip", c.consumerConfig.Skip)
}

func (c *Client) GetClientID() []byte {
return c.clientID
}
9 changes: 7 additions & 2 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/twmb/franz-go/pkg/kgo"
)

var defaultServiceNameKey = "service"
const HeaderServiceKey = "service"

type (
Header = kgo.RecordHeader
Expand Down Expand Up @@ -94,7 +94,7 @@ func NewProducer[T any](client *Client, topic string, opts ...OptionProducer) (*
Topic: topic,
Headers: []Header{
{
Key: defaultServiceNameKey,
Key: HeaderServiceKey,
Value: client.clientID,
},
},
Expand All @@ -116,6 +116,11 @@ type Producer[T any] struct {
produceRaw func(ctx context.Context, records []*Record) error
}

// GetTopic to get producer default topic.
func (p *Producer[T]) GetTopic() string {
return p.config.Topic
}

func (p *Producer[T]) Produce(ctx context.Context, data ...T) error {
records := make([]*Record, 0, len(data))

Expand Down
2 changes: 1 addition & 1 deletion producerdlq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Test_producerDLQ(t *testing.T) {

for _, header := range records[i].Headers {
switch header.Key {
case defaultServiceNameKey:
case HeaderServiceKey:
assert.Equal(t, clientID, header.Value)
case "error":
assert.Equal(t, errDLQStr, string(header.Value))
Expand Down

0 comments on commit adf8acd

Please sign in to comment.