Skip to content

Commit

Permalink
FIX calcule Partition
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelQuetin committed Sep 4, 2024
1 parent ee5b3a6 commit ad44374
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/main/java/fr/abes/bestppn/kafka/TopicProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,10 @@ private void logEnvoi(SendResult<String, ?> result, ProducerRecord<String, ?> re
record.key(), record.value(), metadata.topic(), metadata.partition(), metadata.offset(), Stream.of(result.getProducerRecord().headers().toArray()).map(h -> h.key() + ":" + Arrays.toString(h.value())).collect(Collectors.joining(";"))));
}

public Integer calculatePartition(Integer nbPartitions) throws ArithmeticException {
public Integer calculatePartition(int nbPartitions) throws ArithmeticException {
if (nbPartitions == 0) {
throw new ArithmeticException("Nombre de threads = 0");
}
synchronized (nbPartitions) {
if (lastThreadUsed.incrementAndGet() >= nbPartitions) {
lastThreadUsed.set(0);
}
}

return lastThreadUsed.get();
return lastThreadUsed.getAndIncrement() % nbPartitions;
}
}

0 comments on commit ad44374

Please sign in to comment.