I have the following code to read from Chronicle queue (it's written in Kotlin but that does not matter):
val queue = ChronicleQueueBuilder.single(path).build()
val tailer = queue.createTailer()
tailer.toEnd()
// // This code is wrong
// val lastIndex = tailer.index()
//
// val shift = lastIndex - 10
// if (shift > 0) {
// tailer.moveToIndex(lastIndex)
// }
while (true) {
val text = await(tailer)
if (prefix == null) {
println(text)
} else {
if (text.startsWith(prefix)) {
// Would be nice without additional allocation ...
println(text.substring(prefix.length + 1))
}
}
}
How can I modify the commented code to read previous 10 records from the queue and continue on?
Rationale: It is useful in situations where the queue is used for displaying logs. You want to see a few previous logging statements and see new logging statements as they come.