@@ -38,8 +38,8 @@ import "C"
3838
3939// Producer implements a High-level Apache Kafka Producer instance
4040type Producer struct {
41- Events chan Event
42- ProduceChannel chan * Message
41+ events chan Event
42+ produceChannel chan * Message
4343 handle handle
4444
4545 // Terminates the poller() goroutine
@@ -114,7 +114,7 @@ func (p *Producer) produce(msg *Message, msgFlags int, deliveryChan chan Event)
114114// This is an asynchronous call that enqueues the message on the internal
115115// transmit queue, thus returning immediately.
116116// The delivery report will be sent on the provided deliveryChan if specified,
117- // or on the Producer object's Events channel if not.
117+ // or on the Producer object's Events() channel if not.
118118// Returns an error if message could not be enqueued.
119119func (p * Producer ) Produce (msg * Message , deliveryChan chan Event ) error {
120120 return p .produce (msg , 0 , deliveryChan )
@@ -140,11 +140,21 @@ func (p *Producer) produceBatch(topic string, msgs []*Message, msgFlags int) err
140140 return nil
141141}
142142
143+ // Events returns the Events channel (read)
144+ func (p * Producer ) Events () chan Event {
145+ return p .events
146+ }
147+
148+ // ProduceChannel returns the produce *Message channel (write)
149+ func (p * Producer ) ProduceChannel () chan * Message {
150+ return p .produceChannel
151+ }
152+
143153// Len returns the number of messages and requests waiting to be transmitted to the broker
144154// as well as delivery reports queued for the application.
145155// Includes messages on ProduceChannel.
146156func (p * Producer ) Len () int {
147- return len (p .ProduceChannel ) + len (p .Events ) + int (C .rd_kafka_outq_len (p .handle .rk ))
157+ return len (p .produceChannel ) + len (p .events ) + int (C .rd_kafka_outq_len (p .handle .rk ))
148158}
149159
150160// Flush and wait for outstanding messages and requests to complete delivery.
@@ -162,7 +172,7 @@ func (p *Producer) Flush(timeoutMs int) int {
162172 return p .Len ()
163173 }
164174
165- p .handle .eventPoll (p .Events ,
175+ p .handle .eventPoll (p .events ,
166176 int (math .Min (100 , remain * 1000 )), 1000 , termChan )
167177 }
168178
@@ -175,10 +185,10 @@ func (p *Producer) Close() {
175185 // Wait for poller() (signaled by closing pollerTermChan)
176186 // and channel_producer() (signaled by closing ProduceChannel)
177187 close (p .pollerTermChan )
178- close (p .ProduceChannel )
188+ close (p .produceChannel )
179189 p .handle .waitTerminated (2 )
180190
181- close (p .Events )
191+ close (p .events )
182192
183193 p .handle .cleanup ()
184194
@@ -197,8 +207,8 @@ func (p *Producer) Close() {
197207// go.batch.producer (bool, false) - Enable batch producer (experimental for increased performance).
198208// These batches do not relate to Kafka message batches in any way.
199209// go.delivery.reports (bool, true) - Forward per-message delivery reports to the
200- // Events channel.
201- // go.produce.channel.size (int, 1000000) - ProduceChannel buffer size (in number of messages)
210+ // Events() channel.
211+ // go.produce.channel.size (int, 1000000) - ProduceChannel() buffer size (in number of messages)
202212//
203213func NewProducer (conf * ConfigMap ) (* Producer , error ) {
204214 p := & Producer {}
@@ -241,8 +251,8 @@ func NewProducer(conf *ConfigMap) (*Producer, error) {
241251 p .handle .p = p
242252 p .handle .setup ()
243253 p .handle .rkq = C .rd_kafka_queue_get_main (p .handle .rk )
244- p .Events = make (chan Event , 1000000 )
245- p .ProduceChannel = make (chan * Message , produceChannelSize )
254+ p .events = make (chan Event , 1000000 )
255+ p .produceChannel = make (chan * Message , produceChannelSize )
246256 p .pollerTermChan = make (chan bool )
247257
248258 go poller (p , p .pollerTermChan )
@@ -260,11 +270,11 @@ func NewProducer(conf *ConfigMap) (*Producer, error) {
260270// channel_producer serves the ProduceChannel channel
261271func channelProducer (p * Producer ) {
262272
263- for m := range p .ProduceChannel {
273+ for m := range p .produceChannel {
264274 err := p .produce (m , C .RD_KAFKA_MSG_F_BLOCK , nil )
265275 if err != nil {
266276 m .TopicPartition .Error = err
267- p .Events <- m
277+ p .events <- m
268278 }
269279 }
270280
@@ -280,14 +290,14 @@ func channelBatchProducer(p *Producer) {
280290 totMsgCnt := 0
281291 totBatchCnt := 0
282292
283- for m := range p .ProduceChannel {
293+ for m := range p .produceChannel {
284294 buffered [* m .TopicPartition .Topic ] = append (buffered [* m .TopicPartition .Topic ], m )
285295 bufferedCnt ++
286296
287297 loop2:
288298 for true {
289299 select {
290- case m , ok := <- p .ProduceChannel :
300+ case m , ok := <- p .produceChannel :
291301 if ! ok {
292302 break loop2
293303 }
@@ -315,7 +325,7 @@ func channelBatchProducer(p *Producer) {
315325 if err != nil {
316326 for _ , m = range buffered2 {
317327 m .TopicPartition .Error = err
318- p .Events <- m
328+ p .events <- m
319329 }
320330 }
321331 }
335345 break out
336346
337347 default :
338- _ , term := p .handle .eventPoll (p .Events , 100 , 1000 , termChan )
348+ _ , term := p .handle .eventPoll (p .events , 100 , 1000 , termChan )
339349 if term {
340350 break out
341351 }
0 commit comments