com.networknt.kafka.consumer.AbstractConsumer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kafka-consumer Show documentation
Show all versions of kafka-consumer Show documentation
A module that consumes events from a Kafka topic.
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