SimplePartitioner.java 1001 Bytes
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;
	}

}