Java Code Examples for org.apache.kafka.common.utils.Utils#murmur2()
The following examples show how to use
org.apache.kafka.common.utils.Utils#murmur2() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyModPartitioner.java From SkyEye with GNU General Public License v3.0 | 5 votes |
@Override public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) { List<PartitionInfo> partitions = cluster.partitionsForTopic(topic); int numPartitions = partitions.size(); int partitionNum = 0; try { partitionNum = Utils.murmur2(keyBytes); } catch (Exception e) { partitionNum = key.hashCode(); } return Math.abs(partitionNum % numPartitions); }
Example 2
Source File: PartitionTest.java From SkyEye with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { String app = "app-test1"; String host = "jthink"; int numPartitions = 9; String key = new StringBuilder(app).append(host).toString(); byte[] keyBytes= ByteBuffer.allocate(4).putInt(key.hashCode()).array(); int partitionNum = 0; try { partitionNum = Utils.murmur2(keyBytes); } catch (Exception e) { partitionNum = key.hashCode(); } System.out.println(Math.abs(partitionNum % numPartitions)); }
Example 3
Source File: KafkaMQClientHandler.java From Thunder with Apache License 2.0 | 5 votes |
@SuppressWarnings("resource") private int getPartitionIndex(Consumer<String, byte[]> consumer, String topic, String key) { int partitionNumber = consumer.partitionsFor(topic).size(); StringSerializer keySerializer = new StringSerializer(); byte[] serializedKey = keySerializer.serialize(topic, key); int positive = Utils.murmur2(serializedKey) & 0x7fffffff; return positive % partitionNumber; }
Example 4
Source File: KafkaTest.java From Thunder with Apache License 2.0 | 5 votes |
@SuppressWarnings("resource") private int getPartitionIndex(int partitionNumber, String topic, String key) { StringSerializer keySerializer = new StringSerializer(); byte[] serializedKey = keySerializer.serialize(topic, key); int positive = Utils.murmur2(serializedKey) & 0x7fffffff; return positive % partitionNumber; }
Example 5
Source File: DefaultMessage.java From azeroth with Apache License 2.0 | 4 votes |
public long getPartitionHash() { if (partitionHash <= 0 && partitionFactor != null) { partitionHash = Utils.murmur2(partitionFactor.toString().getBytes()); } return partitionHash; }