Package org.nuxeo.lib.stream.log.kafka
Class KafkaLogTailer<M extends Externalizable>
java.lang.Object
org.nuxeo.lib.stream.log.kafka.KafkaLogTailer<M>
- All Implemented Interfaces:
AutoCloseable,org.apache.kafka.clients.consumer.ConsumerRebalanceListener,LogTailer<M>
public class KafkaLogTailer<M extends Externalizable>
extends Object
implements LogTailer<M>, org.apache.kafka.clients.consumer.ConsumerRebalanceListener
- Since:
- 9.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected org.apache.kafka.clients.consumer.KafkaConsumer<String,org.apache.kafka.common.utils.Bytes> protected static final AtomicIntegerprotected booleanprotected final Nameprotected Stringprotected booleanprotected booleanprotected booleanprotected intprotected longprotected RebalanceListenerprotected Collection<Name>protected Collection<LogPartition>protected final Queue<org.apache.kafka.clients.consumer.ConsumerRecord<String,org.apache.kafka.common.utils.Bytes>> protected final NameResolverprotected Collection<org.apache.kafka.common.TopicPartition> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedKafkaLogTailer(Codec<M> codec, NameResolver resolver, Name group, Properties consumerProps) -
Method Summary
Modifier and TypeMethodDescriptionReturns the list of Log name, partitions tuples currently assigned to this tailer.protected static StringbuildId(Name group, Collection<LogPartition> partitions) protected static StringbuildSubscribeId(Name group, Collection<Name> names) protected voidvoidclose()booleanclosed()Returnstrueif the tailer has been closed.voidcommit()Commit current positions for all partitions (last message offset returned by read).commit(LogPartition partition) Commit current position for the partition.static <M extends Externalizable>
KafkaLogTailer<M>createAndAssign(Codec<M> codec, NameResolver resolver, Collection<LogPartition> partitions, Name group, Properties consumerProps) static <M extends Externalizable>
KafkaLogTailer<M>createAndSubscribe(Codec<M> codec, NameResolver resolver, Collection<Name> names, Name group, Properties consumerProps, RebalanceListener listener) protected voidCommits the consumer at its current position regardless of lastOffsets or lastCommittedOffsetsgetCodec()Returns the codec used to read the records.group()Returns the consumer group.offsetForTimestamp(LogPartition partition, long timestamp) Look up the offset for the given partition by timestamp.voidonPartitionsAssigned(Collection<org.apache.kafka.common.TopicPartition> newPartitions) voidonPartitionsLost(Collection<org.apache.kafka.common.TopicPartition> partitions) voidonPartitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions) protected intRead a message from assigned partitions within the timeout.voidreset()Reset all committed positions for this group, next read will be done from beginning.voidreset(LogPartition partition) Reset the committed position for this group on this partition, next read for this partition will be done from the beginning.voidSet the current position for a single partition.voidtoEnd()Set the current positions to the end of all partitions.voidSet the current positions to previously committed positions.protected longtoLastCommitted(org.apache.kafka.common.TopicPartition topicPartition) voidtoStart()Set the current positions to the beginning of all partitions.toString()
-
Field Details
-
group
-
lastOffsets
-
lastCommittedOffsets
-
records
-
codec
-
decodeCodec
-
resolver
-
consumer
protected org.apache.kafka.clients.consumer.KafkaConsumer<String,org.apache.kafka.common.utils.Bytes> consumer -
id
-
topicPartitions
-
partitions
-
closed
protected boolean closed -
names
-
listener
-
isRebalanced
protected boolean isRebalanced -
isRevoked
protected boolean isRevoked -
isLost
protected boolean isLost -
consumerMoved
protected boolean consumerMoved -
CONSUMER_CLIENT_ID_SEQUENCE
-
lastPollTimestamp
protected long lastPollTimestamp -
lastPollSize
protected int lastPollSize
-
-
Constructor Details
-
KafkaLogTailer
protected KafkaLogTailer(Codec<M> codec, NameResolver resolver, Name group, Properties consumerProps)
-
-
Method Details
-
createAndAssign
public static <M extends Externalizable> KafkaLogTailer<M> createAndAssign(Codec<M> codec, NameResolver resolver, Collection<LogPartition> partitions, Name group, Properties consumerProps) -
createAndSubscribe
public static <M extends Externalizable> KafkaLogTailer<M> createAndSubscribe(Codec<M> codec, NameResolver resolver, Collection<Name> names, Name group, Properties consumerProps, RebalanceListener listener) -
buildId
-
buildSubscribeId
-
read
Description copied from interface:LogTailerRead a message from assigned partitions within the timeout.- Specified by:
readin interfaceLogTailer<M extends Externalizable>- Returns:
- null if there is no message in the queue after the timeout.
- Throws:
InterruptedException
-
poll
- Throws:
InterruptedException
-
toEnd
public void toEnd()Description copied from interface:LogTailerSet the current positions to the end of all partitions.- Specified by:
toEndin interfaceLogTailer<M extends Externalizable>
-
toStart
public void toStart()Description copied from interface:LogTailerSet the current positions to the beginning of all partitions.- Specified by:
toStartin interfaceLogTailer<M extends Externalizable>
-
toLastCommitted
public void toLastCommitted()Description copied from interface:LogTailerSet the current positions to previously committed positions.- Specified by:
toLastCommittedin interfaceLogTailer<M extends Externalizable>
-
toLastCommitted
protected long toLastCommitted(org.apache.kafka.common.TopicPartition topicPartition) -
seek
Description copied from interface:LogTailerSet the current position for a single partition. Do not change other partitions positions.- Specified by:
seekin interfaceLogTailer<M extends Externalizable>
-
reset
public void reset()Description copied from interface:LogTailerReset all committed positions for this group, next read will be done from beginning.- Specified by:
resetin interfaceLogTailer<M extends Externalizable>
-
reset
Description copied from interface:LogTailerReset the committed position for this group on this partition, next read for this partition will be done from the beginning.- Specified by:
resetin interfaceLogTailer<M extends Externalizable>
-
offsetForTimestamp
Description copied from interface:LogTailerLook up the offset for the given partition by timestamp. The position is the earliest offset whose timestamp is greater than or equal to the given timestamp.The timestamp used depends on the implementation, for Kafka this is the LogAppendTime. Returns null if no record offset is found with an appropriate timestamp.
- Specified by:
offsetForTimestampin interfaceLogTailer<M extends Externalizable>
-
commit
public void commit()Description copied from interface:LogTailerCommit current positions for all partitions (last message offset returned by read).- Specified by:
commitin interfaceLogTailer<M extends Externalizable>
-
forceCommit
protected void forceCommit()Commits the consumer at its current position regardless of lastOffsets or lastCommittedOffsets -
commit
Description copied from interface:LogTailerCommit current position for the partition.- Specified by:
commitin interfaceLogTailer<M extends Externalizable>- Returns:
- the committed offset, can return null if there was no previous read done on this partition.
-
assignments
Description copied from interface:LogTailerReturns the list of Log name, partitions tuples currently assigned to this tailer. Assignments can change only if the tailer has been created usingLogManager.subscribe(org.nuxeo.lib.stream.log.Name, java.util.Collection<org.nuxeo.lib.stream.log.Name>, org.nuxeo.lib.stream.log.RebalanceListener, org.nuxeo.lib.stream.codec.Codec<M>).- Specified by:
assignmentsin interfaceLogTailer<M extends Externalizable>
-
group
Description copied from interface:LogTailerReturns the consumer group.- Specified by:
groupin interfaceLogTailer<M extends Externalizable>
-
closed
public boolean closed()Description copied from interface:LogTailerReturnstrueif the tailer has been closed.- Specified by:
closedin interfaceLogTailer<M extends Externalizable>
-
getCodec
Description copied from interface:LogTailerReturns the codec used to read the records. A null codec is the default legacy encoding.- Specified by:
getCodecin interfaceLogTailer<M extends Externalizable>
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLogTailer<M extends Externalizable>
-
toString
-
onPartitionsRevoked
- Specified by:
onPartitionsRevokedin interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener
-
onPartitionsAssigned
- Specified by:
onPartitionsAssignedin interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener
-
onPartitionsLost
- Specified by:
onPartitionsLostin interfaceorg.apache.kafka.clients.consumer.ConsumerRebalanceListener
-
cleanDuringRebalancing
protected void cleanDuringRebalancing()
-