Sarama Version: 1.22.1
Kafka Version: 1.1.1
Go Version:1.12
Hello, how we can make health check with sarama.AsyncProducer?
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.
Most helpful comment
Resolve that using
sarama.NewAsyncProducerFromClient(saramaClient):Attach client to internal struct:
And create method
IsHealthyIts look like tricky, but its works for me)