Browse Source

Add an example for different partitioning per topic.

Willem van Bergen 10 years ago
parent
commit
faec514115
1 changed files with 16 additions and 0 deletions
  1. 16 0
      partitioner_test.go

+ 16 - 0
partitioner_test.go

@@ -180,3 +180,19 @@ func ExamplePartitioner_manual() {
 
 	log.Printf("Produced message to partition %d with offset %d", partition, offset)
 }
+
+// This example shows how to set a different partitioner depending on the topic.
+func ExamplePartitioner_per_topic() {
+	config := NewConfig()
+	config.Producer.Partitioner = func(topic string) Partitioner {
+		switch topic {
+		case "access_log", "error_log":
+			return NewRandomPartitioner(topic)
+
+		default:
+			return NewHashPartitioner(topic)
+		}
+	}
+
+	// ...
+}