All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ddth.kafka.internal.RoundRobinPartitioner Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
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