Skip to content

Commit

Permalink
improvement(kafkax): add close for wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
yinheli committed Aug 30, 2021
1 parent a172447 commit aeb3a9f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/kafkax/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Client interface {
// Get get kafka client
Get() sarama.Client

// Close close kafka client
Close() error

// SendMessage send message to kafka
SendMessage(ctx context.Context, message *sarama.ProducerMessage) error

Expand Down Expand Up @@ -102,6 +105,14 @@ func (t *defaultKafka) Get() sarama.Client {
return t.client
}

// Close close kafka client
func (t *defaultKafka) Close() error {
if !t.client.Closed() {
return t.client.Close()
}
return nil
}

// SendMessage send message to kafka
func (t *defaultKafka) SendMessage(ctx context.Context, message *sarama.ProducerMessage) (err error) {
if err := t.initializeProducer(ctx); err != nil {
Expand Down

0 comments on commit aeb3a9f

Please sign in to comment.