소스 검색

Add an example for different partitioning per topic.

Willem van Bergen 11 년 전
부모
커밋
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)
 	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)
+		}
+	}
+
+	// ...
+}