SimplePartitioner.java
1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.sitech.kafka;
import kafka.producer.Partitioner;
import kafka.utils.VerifiableProperties;
/**
* SimplePartitioner.java
*
* ���� �ܡ����Զ�������㷨
* ���� ������SimplePartitioner
*
* �������������
*
* ���� �汾 ���� �������
* -------------------------------------------
* 2015-3-12 v1.0 dongyj �¹�����
*
*
*
* ���� Ȩ����
* Copyright (c) 2015 : ~SI-TECH~.
*
*/
public class SimplePartitioner implements Partitioner<String>{
public SimplePartitioner (VerifiableProperties props) {
}
@Override
public int partition(String key, int a_numPartitions) {
int partition = 0;
int offset = key.lastIndexOf('.');
if(offset > 0){
partition = Integer.parseInt(key.substring(offset+1)) % a_numPartitions;
}
return partition;
}
}