ソースを参照

Add an example for different partitioning per topic.

Willem van Bergen 10 年 前
コミット
faec514115
1 ファイル変更16 行追加0 行削除
  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)
+		}
+	}
+
+	// ...
+}