Kafka中Consumer类源码介绍

Kafka中Consumer源码

public interface Consumer<K, V> extends Closeable {
    void subscribe(String... var1);

    void subscribe(TopicPartition... var1);

    void unsubscribe(String... var1);

    void unsubscribe(TopicPartition... var1);

    Map<String, ConsumerRecords<K, V>> poll(long var1);

    OffsetMetadata commit(boolean var1);

    OffsetMetadata commit(Map<TopicPartition, Long> var1, boolean var2);

    void seek(Map<TopicPartition, Long> var1);

    Map<TopicPartition, Long> position(Collection<TopicPartition> var1);

    Map<TopicPartition, Long> committed(Collection<TopicPartition> var1);

    Map<TopicPartition, Long> offsetsBeforeTime(long var1, Collection<TopicPartition> var3);

    Map<MetricName, ? extends Metric> metrics();

    void close();
}
Closeable源码

public interface Closeable {

    /**
     * Closes this stream and releases any system resources associated
     * with it. If the stream is already closed then invoking this 
     * method has no effect. 
     *
     * @throws IOException if an I/O error occurs
     */
    public void close() throws IOException;

}
TopicPartition源码

public final class TopicPartition {
    private int hash = 0;
    private final int partition;
    private final String topic;

    public TopicPartition(String topic, int partition) {
        this.partition = partition;
        this.topic = topic;
    }

    public int partition() {
        return this.partition;
    }

    public String topic() {
        return this.topic;
    }

    public int hashCode() {
        if(this.hash != 0) {
            return this.hash;
        } else {
            boolean prime = true;
            byte result = 1;
            int result1 = 31 * result + this.partition;
            result1 = 31 * result1 + (this.topic == null?0:this.topic.hashCode());
            this.hash = result1;
            return result1;
        }
    }

    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        } else if(obj == null) {
            return false;
        } else if(this.getClass() != obj.getClass()) {
            return false;
        } else {
            TopicPartition other = (TopicPartition)obj;
            if(this.partition != other.partition) {
                return false;
            } else {
                if(this.topic == null) {
                    if(other.topic != null) {
                        return false;
                    }
                } else if(!this.topic.equals(other.topic)) {
                    return false;
                }

                return true;
            }
        }
    }

    public String toString() {
        return this.topic + "-" + this.partition;
    }
}

OffsetMetadata源码

public final class OffsetMetadata {
    private final Map<TopicPartition, Long> offsets;
    private final Map<TopicPartition, RuntimeException> errors;

ConsumerRecords源码

public class ConsumerRecords<K, V> {
    private final String topic;
    private final Map<Integer, List<ConsumerRecord<K, V>>> recordsPerPartition;


MetricName源码

public final class MetricName {
    private final String name;
    private final String group;
    private final String description;
    private Map<String, String> tags;
    private int hash;





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值