kafka-按键分区

配置
        # 自定义分区
# partitioner:
# class: com.dfree.data.config.PartitionerByKey
代码

//public class PartitionerByKey implements Partitioner {
// @Override
// public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
// int numPartitions = cluster.partitionCountForTopic(topic);
// return Math.abs(key.hashCode()) % numPartitions;
// // TODO: 2024/1/11 雪花id Long
//// return Math.abs(key.hashCode()) % numPartitions;
// }
//
// @Override
// public void close() {
//
// }
//
// @Override
// public void configure(Map<String, ?> map) {
//
// }
//}


 
posted on 2024-03-21 08:55  daofree  阅读(10)  评论(0编辑  收藏  举报