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

com.networknt.kafka.consumer.AbstractConsumer Maven / Gradle / Ivy

The newest version!
package com.networknt.kafka.consumer;

import com.networknt.config.Config;
import com.networknt.kafka.common.KafkaConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;

public abstract class AbstractConsumer implements LightConsumer {
    static private final Logger logger = LoggerFactory.getLogger(AbstractConsumer.class);

    /** indicate the thread should be stopped */
    private final AtomicBoolean stopped = new AtomicBoolean(false);
    public KafkaConsumer consumer;

    static private Map properties;

    static final KafkaConsumerConfig config = (KafkaConsumerConfig) Config.getInstance().getJsonObjectConfig(KafkaConsumerConfig.CONFIG_NAME, KafkaConsumerConfig.class);

    @Override
    public void open() {
        consumer = new KafkaConsumer<>(config.getProperties());
    }

    @Override
    public void close() {
        stopped.getAndSet(true);
        if(consumer != null) consumer.close();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy