sarama icon indicating copy to clipboard operation
sarama copied to clipboard

Producer problem

Open steven0711dong opened this issue 3 years ago • 0 comments

Versions

Please specify real version numbers or git SHAs, not just "Latest" since that changes fairly regularly.

| Sarama | Kafka | Go | |1.31.1|2.8.0|1.17.3|

Configuration

What configuration values are you using for Sarama and Kafka?


//kafkaVersion := "2.6.0"
	kafkaConfig = sarama.NewConfig()
	// if kafkaConfig.Version, err = sarama.ParseKafkaVersion(kafkaVersion); err != nil {
	// 	return nil, err
	// }
	// Use OffsetOldest instead of OffsetOldest. This will pull any lingering
	// messages from the queue when the provider starts
	kafkaConfig.ClientID = "producetest"
	kafkaConfig.Producer.Partitioner = sarama.NewRoundRobinPartitioner
	kafkaConfig.Producer.RequiredAcks = sarama.WaitForLocal
	kafkaConfig.Producer.Return.Successes = false
	kafkaConfig.Producer.Return.Errors = true
	kafkaConfig.Net.SASL.Enable = true
	kafkaConfig.Net.SASL.Mechanism = sarama.SASLTypePlaintext
	kafkaConfig.Net.TLS.Enable = true
	kafkaConfig.Net.TLS.Config = &tls.Config{
		MinVersion:               tls.VersionTLS12,
		MaxVersion:               tls.VersionTLS12,
		PreferServerCipherSuites: true,
	}
	kafkaConfig.Net.SASL.User = user
	kafkaConfig.Net.SASL.Password = apiKey

Logs

When filing an issue please provide logs from Sarama and Kafka if at all possible. You can set sarama.Logger to a log.Logger to capture Sarama debug output.

logs: CLICK ME

Problem Description

Hello, Looking for some guidance on why this piece of producer code won’t work. I’m producing to a topic as the following:

for msg := range p.messages {
		producer.Input() <- msg
		select {
		case err := <-producer.Errors():
			fmt.Println("Failed to produce message", err)
		case success := <-producer.Successes():
			fmt.Printf("Sent message value='%s' at partition = %d, offset = %d\n", success.Value, success.Partition, success.Offset)
		default:
			//do something else 

p.messages is a buffered channel that can hold up to 1000 sarama.ProduceMessages. What I noticed so far is the following: If we set config.Producer.Return.Successes = false, all messages are successfully produced to our topic and we received all of them. If we set config.Producer.Return.Successes =true, some messages were not successfully produced to our topic and we miss messages.

steven0711dong avatar Feb 18 '22 14:02 steven0711dong