Browse Source

Default to hash partitioner

This is what the scala client defaults to
Evan Huus 11 years ago
parent
commit
c476f0db1b
2 changed files with 4 additions and 3 deletions
  1. 2 2
      producer.go
  2. 2 1
      simple_producer.go

+ 2 - 2
producer.go

@@ -15,7 +15,7 @@ type PartitionerConstructor func() Partitioner
 
 // ProducerConfig is used to pass multiple configuration options to NewProducer.
 type ProducerConfig struct {
-	Partitioner       PartitionerConstructor // Generates partitioners for choosing the partition to send messages to (defaults to random).
+	Partitioner       PartitionerConstructor // Generates partitioners for choosing the partition to send messages to (defaults to hash).
 	RequiredAcks      RequiredAcks           // The level of acknowledgement reliability needed from the broker (defaults to WaitForLocal).
 	Timeout           time.Duration          // The maximum duration the broker will wait the receipt of the number of RequiredAcks. This is only relevant when RequiredAcks is set to WaitForAll or a number > 1. Only supports millisecond resolution, nanoseconds will be truncated.
 	Compression       CompressionCodec       // The type of compression to use on messages (defaults to no compression).
@@ -30,7 +30,7 @@ type ProducerConfig struct {
 // NewProducerConfig creates a new ProducerConfig instance with sensible defaults.
 func NewProducerConfig() *ProducerConfig {
 	return &ProducerConfig{
-		Partitioner:     NewRandomPartitioner,
+		Partitioner:     NewHashPartitioner,
 		RequiredAcks:    WaitForLocal,
 		MaxMessageBytes: 1000000,
 	}

+ 2 - 1
simple_producer.go

@@ -9,7 +9,8 @@ type SimpleProducer struct {
 }
 
 // NewSimpleProducer creates a new SimpleProducer using the given client, topic and partitioner. If the
-// partitioner is nil, messages are partitioned randomly.
+// partitioner is nil, messages are partitioned by the hash of the key
+// (or randomly if there is no key).
 func NewSimpleProducer(client *Client, topic string, partitioner PartitionerConstructor) (*SimpleProducer, error) {
 	if topic == "" {
 		return nil, ConfigurationError("Empty topic")