com.github.ddth.kafka.internal.RoundRobinPartitioner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ddth-kafka Show documentation
Show all versions of ddth-kafka Show documentation
DDTH's Kafka Libraries and Utilities
package com.github.ddth.kafka.internal;
import java.util.concurrent.atomic.AtomicInteger;
import kafka.producer.Partitioner;
import kafka.utils.VerifiableProperties;
/**
* A round-robin {@link Partitioner} implementation.
*
* @author Thanh Ba Nguyen
* @since 1.0.1
*/
public class RoundRobinPartitioner implements Partitioner {
private AtomicInteger counter = new AtomicInteger(0);
public RoundRobinPartitioner() {
}
public RoundRobinPartitioner(VerifiableProperties props) {
}
public void init(VerifiableProperties props) {
}
/**
* {@inheritDoc}
*/
@Override
public int partition(Object key, int numPartitions) {
int result = counter.incrementAndGet() % numPartitions;
counter.set(result);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy