配置props.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, RoundRobinPartitioner.class);
public Map<String,Object> producerConfigs(){Map<String,Object> props = new HashMap<>();props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,bootstrapServers);props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,valueSerializer);props.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, RoundRobinPartitioner.class);return props;
}public ProducerFactory producerFactory(){return new DefaultKafkaProducerFactory<>(producerConfigs());
}// 覆盖spring-kafka中的配置
@Bean
public KafkaTemplate<String,Object> kafkaTemplate(){return new KafkaTemplate<String,Object>(producerFactory());
}