K - Key typeV - Value typepublic class BlockingQueueConsumer<K,V>
extends java.lang.Object
implements org.apache.kafka.clients.consumer.ConsumerRebalanceListener
BlockingQueues. Each assigned partition will relay its messages to its own queue.
In addition, each queue has a consuming process/thread. Once a message has been "processed" successfully its offset
will be marked to be committed.| Constructor and Description |
|---|
BlockingQueueConsumer(java.lang.String topic,
java.util.Properties kafkaConfig,
int queueSize,
java.util.function.Consumer<V> action)
This constructor immediately connects to the kafka broker and creates a
Processor for each assigned
partition. |
| Modifier and Type | Method and Description |
|---|---|
void |
onPartitionsAssigned(java.util.Collection<org.apache.kafka.common.TopicPartition> partitions) |
void |
onPartitionsRevoked(java.util.Collection<org.apache.kafka.common.TopicPartition> partitions) |
void |
start()
Start consuming/ relaying messages to the processors.
|
void |
stop()
Stops all background activities: kafka message consumption, message relay and processing.
|
public BlockingQueueConsumer(java.lang.String topic,
java.util.Properties kafkaConfig,
int queueSize,
java.util.function.Consumer<V> action)
Processor for each assigned
partition.topic - The topic to subscribe tokafkaConfig - Kafka client configurationqueueSize - Size of the BlockingQueues for each Processoraction - Consumer of the transported messagejava.lang.IllegalArgumentException - if problems are found with the configpublic void start()
java.lang.IllegalStateException - in case the consumer has been started beforepublic void stop()
java.lang.IllegalArgumentException - in case the consumer has not been startedpublic void onPartitionsAssigned(java.util.Collection<org.apache.kafka.common.TopicPartition> partitions)
onPartitionsAssigned in interface org.apache.kafka.clients.consumer.ConsumerRebalanceListenerpublic void onPartitionsRevoked(java.util.Collection<org.apache.kafka.common.TopicPartition> partitions)
onPartitionsRevoked in interface org.apache.kafka.clients.consumer.ConsumerRebalanceListener