Package org.eso.ias.kafkautils
Class SimpleStringConsumer
java.lang.Object
org.eso.ias.kafkautils.KafkaStringsConsumer
org.eso.ias.kafkautils.SimpleStringConsumer
- All Implemented Interfaces:
Runnable
,org.apache.kafka.clients.consumer.ConsumerRebalanceListener
,KafkaStringsConsumer.StringsConsumer
- Direct Known Subclasses:
ReplyKafkaConsumer
public class SimpleStringConsumer
extends KafkaStringsConsumer
implements KafkaStringsConsumer.StringsConsumer
/**
Generic Kafka consumer to get strings from a kafka topic.
The strings are passed one at a time to the listener for further processing.
This class is inefficient compared to KafkaStringsConsumer
that allows to process
bounce of events in one single call.
- Author:
- acaproni
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The listener to be notified of strings read from the kafka topic.Nested classes/interfaces inherited from class org.eso.ias.kafkautils.KafkaStringsConsumer
KafkaStringsConsumer.StreamPosition, KafkaStringsConsumer.StringsConsumer
-
Field Summary
Fields inherited from class org.eso.ias.kafkautils.KafkaStringsConsumer
DEFAULT_CONSUMER_READY_TIMEOUT, MIN_CONSUMER_READY_TIMEOUT, topicName, WAIT_CONSUMER_READY_TIMEOUT_PROP_NAME
-
Constructor Summary
ConstructorDescriptionSimpleStringConsumer
(String servers, String topicName, String consumerID) Constructor -
Method Summary
Modifier and TypeMethodDescriptionlong
void
startGettingStrings
(KafkaStringsConsumer.StreamPosition startReadingFrom, SimpleStringConsumer.KafkaConsumerListener listener) Start polling events from the kafka channel.void
stringsReceived
(Collection<String> strings) Sends the strings received from the kafka topic to the listenerMethods inherited from class org.eso.ias.kafkautils.KafkaStringsConsumer
getNumOfProcessedRecords, isReady, onPartitionsAssigned, onPartitionsLost, onPartitionsRevoked, run, seekTo, setUp, setUp, startGettingEvents, tearDown, waitUntilConsumerReady
-
Constructor Details
-
SimpleStringConsumer
Constructor- Parameters:
servers
- The kafka servers to connect totopicName
- The name of the topic to get events fromconsumerID
- the ID of the consumer
-
-
Method Details
-
startGettingStrings
public void startGettingStrings(KafkaStringsConsumer.StreamPosition startReadingFrom, SimpleStringConsumer.KafkaConsumerListener listener) throws KafkaUtilsException Start polling events from the kafka channel.This method starts the thread that polls the kafka topic and returns after the consumer has been assigned to at least one partition.
- Parameters:
startReadingFrom
- Starting position in the kafka partitionlistener
- The listener of events published in the topic- Throws:
KafkaUtilsException
- in case of timeout subscribing to the kafkatopic
-
stringsReceived
Sends the strings received from the kafka topic to the listener- Specified by:
stringsReceived
in interfaceKafkaStringsConsumer.StringsConsumer
-
getNumOfProcessedStrings
public long getNumOfProcessedStrings()- Returns:
- the number of strings processed
-