com.github.hackerwin7.jlib.utils.executors.KafkaDefaultPartitionKeyExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jlib-utils Show documentation
Show all versions of jlib-utils Show documentation
utils set for java projects
package com.github.hackerwin7.jlib.utils.executors;
import org.apache.commons.lang3.StringUtils;
import java.util.Random;
/**
* Created by IntelliJ IDEA.
* User: hackerwin7
* Date: 2015/12/17
* Time: 11:45 AM
* Desc:
*/
public class KafkaDefaultPartitionKeyExecutor {
public static void main(String[] args) throws Exception {
String ss = "2269082,2269083,2269084,2269085,2269087,2269086,2269089,2269088,2269091,2269090,1530009,2216915,2216916,2216917,2216918,2216919,2216920,2216921,2216922,2216923,2216924,2216925,2216926,2216927,2216928,2216929,2216930,2216931,2216932,2216933,2216934,2216935,2216936,2216937,2216938,2216939,2216940,2216941,2216942,2216943,2216944,2216945,2216946,2216947,2216948,2216949,2088799,2639503,2216945,2216930,2216936,2216943,2216918,2216948,2216928,2216915,2216925,2216937,2216946,2216922,2216921,2216935,2216939,2216938,2216933,2216934,2216931,2216916,2216941,2216919,2216926,2216940,2216929,2216927,2216947,2216917,2216949,2216924,2216932,2216923,2216944,2216920,2216942,2639503,2088799,2088800,2088801,2088802,2088803,2088804,2088805,2088806,2088807,1649702,1332540,2345480,1332540,3181969,2298161,1929477,1929476,1929481,1929480,1929479,1929478,2049565,2010063,2049564,2010059,2010064,2010061,2049561,2010062,2049562,2049563,2185200,1936932,2010065,2010060,2055711,2079401,2079402,2079403,2079404,2079405,2079406,2079407,2079408,2079409,2079410,2079411,2079412,2079413,2079414,2079415,2079416,2079417,2079418,2079419,2079420,2079421,2079422,2079423,2079424,2079425,2079426,2079427,2079428,2079429,2079430,2079431,2079432,2079433,2079434,2079435,2079436,2079437,2079438,2079439,2079440,2079441,2079442,2079443,2079444,2079445,2079446,2079447,2079448,2079449,2079450,2079451,2079452,2079453,2079454,2079455,2079456,2079457,2079458,2079459,2079460,2079461,2079462,2079463,2079464,2079465,2079466,2079467,2079468,2079469,2079470,2079471,2079472,2079473,2079474,2079475,2079476,2079477,2079478,2079479,2079480,2079481,2079482,2079483,2079484,2079485,2079486,2079487,2079488,2079489,2079490,2079491,3181969,2107123,1776642,2079462,2079451,2079487,2079415,2079475,2079472,2079445,2079414,2079480,2079422,2079450,2079426,2079452,2079469,2079427,2079437,2079456,2079433,2079460,2079491,2079409,2079468,2079434,2079449,2079485,2079471,2079429,2079447,2079461,2079410,2079432,2079478,2079486,2079420,2079477,2079430,2079444,2079440,2079473,2079442,2079403,2079412,2079419,2079431,2079474,2079443,2079446,2079479,2079411,2079402,2079453,2079457,2079490,2079401,2079466,2079436,2079455,2079476,2079405,2079439,2079428,2079483,2079416,2079488,2079448,2079463,2079438,2079424,2079465,2079404,2079418,2079484,2079458,2079441,2079407,2079459,2079423,2079425,2079435,2079454,2079482,2079470,2079417,2079413,2079467,2079481,2079421,2079408,2079464,2079489,2079406,2088801,2088806,2088807,2088805,2088802,2088799,2088804,2088803,2088800";
String[] ssArr = StringUtils.split(ss, ",");
for(String id : ssArr) {
System.out.println(id + " => " + new kafka.producer.DefaultPartitioner(null).partition(id, 8));
}
}
public static int partition(String key, int numPartitions) {
if(StringUtils.isBlank(key))
return new Random().nextInt(numPartitions);
else
return Math.abs(key.hashCode()) % numPartitions;
}
}