Closed Zaazik closed 5 years ago
Resolve that using sarama.NewAsyncProducerFromClient(saramaClient)
:
func NewProducer(saramaCfg *sarama.Config, brokers []string) (*Producer, error) {
saramaClient, err := sarama.NewClient(brokers, saramaCfg)
if err!=nil{
return nil, err
}
saramaProducer, err := sarama.NewAsyncProducerFromClient(saramaClient)
if err != nil {
return nil, errors.WithStack(err)
}
producer := &Producer{client:saramaClient, saramaProducer: saramaProducer}
return producer, nil
}
Attach client to internal struct:
type Producer struct {
client sarama.Client
saramaProducer sarama.AsyncProducer
}
And create method IsHealthy
func (p *Producer) IsHealthy() bool {
return len(p.client.Brokers()) > 0
}
Its look like tricky, but its works for me)
Hey @Zaazik it seems you found an answer for this, can this issue be closed?
seems it's already resolved, feel free to re-open the issue if need more help.
@Zaazik Can this feature be integrated into the standard version? @d1egoaz
Versions
Sarama Version: 1.22.1 Kafka Version: 1.1.1 Go Version:1.12
Problem Description
Hello, how we can make health check with sarama.AsyncProducer?