浏览代码

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)
+		}
+	}
+
+	// ...
+}