Closed iAziz786 closed 3 years ago
Here is what I'm doing right now with the Produce()
method.
type KafkaProducer struct {
producer *kafka.Producer
}
func (kp *KafkaProducer) Produce(msg *kafka.Message, fn func(error)) error {
deliveryChan := make(chan kafka.Event)
go func() {
e := <-deliveryChan
if m, ok := e.(*kafka.Message); ok {
fn(m.TopicPartition.Error)
}
}()
return kp.producer.Produce(msg, deliveryChan)
}
Yep, your deliveryChan is the private (or rather user-specified) delivery channel, as opposed to the default p.Events() channel.
@edenhill Yes, but how can I pass the private channel to producer.ProducerChannel()?
Description
In the README it's mentioned that we can use private channel with
producer.ProducerChannel()
I'm not able to find how to do so since the example which is given is using theproducer.Events()
function.My use case is that I wanted to inform the caller of the
ProducerChannel
by a call back function if any error occurs therefore I need the private channel for that. I know I can do it withproducer.Produce()
but wanted to know how it is possible with producer channel.