use the goalng "github.com/Shopify/sarama" library
I now have two consumers, and the two topic,kafka partitions are set to 50, but in the actual operation, only one consumer is consuming, closing the consumers who can currently consume, and the other can also consume, but it is not possible to run it at the same time
look at the documents on the Internet because there are not enough partitions, but now I have set 50 partitions, and there are only two consumers
code 1
producerConfig := sarama.NewConfig()
producerConfig.Producer.Partitioner = sarama.NewHashPartitioner
producerConfig.Producer.Return.Successes = true
producerConfig.Producer.Timeout = 5 * time.Second
producer, err = sarama.NewSyncProducer([broker], producerConfig)
kafka_msg := &sarama.ProducerMessage{
Topic:topic,
Key:sarama.StringEncoder(key),
Value: sarama.StringEncoder(value),
}
partition, offset, err := producer.SendMessage(kafka_msg)
in this way, the partition id returned after successful delivery is always 0. I wonder if it is because my partition setting value does not take effect.
, but not sure because it is the first time to use kafka,
then use the next method
Code 2
producerConfig := sarama.NewConfig()
// producerConfig.Producer.Partitioner = sarama.NewHashPartitioner
producerConfig.Producer.Return.Successes = true
producerConfig.Producer.Timeout = 5 * time.Second
producer, err = sarama.NewSyncProducer([broker], producerConfig)
kafka_msg := &sarama.ProducerMessage{
Topic:topic,
Key:sarama.StringEncoder(key),
Value: sarama.StringEncoder(value),
Partition: 7 ,
}
partition, offset, err := producer.SendMessage(kafka_msg)
after this setting, the partition returns 0 for successful delivery.
what I want to make sure is that before the partition setting takes effect, if I write in code 2, will the final partition be delivered to 7?
I suspect now that the partition configuration does not take effect
Please answer