33 lines
744 B
Java
33 lines
744 B
Java
package com.muyu.mqttmessage.config.kafkaconfig;
|
||
|
||
import org.apache.kafka.clients.producer.Partitioner;
|
||
import org.apache.kafka.common.Cluster;
|
||
import org.springframework.stereotype.Component;
|
||
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* @ClassName CustomizePartitioner
|
||
* @Description kafka自定义分区
|
||
* @Author Xin.Yao
|
||
* @Date 2024/6/7 下午8:05
|
||
*/
|
||
@Component
|
||
public class CustomizePartitioner implements Partitioner {
|
||
@Override
|
||
public int partition(String s, Object o, byte[] bytes, Object o1, byte[] bytes1, Cluster cluster) {
|
||
//自定义分区规则,默认全部发送到0号分区
|
||
return 0;
|
||
}
|
||
|
||
@Override
|
||
public void close() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void configure(Map<String, ?> map) {
|
||
|
||
}
|
||
}
|