how to the the unread msg count? it seems the queue.lastIndex() changes very largely only when one msg is added
useryq8 opened this issue · 1 comments
java 21.0.1
'net.openhft:chronicle-queue:5.25ea10'
usage:
consumerTailer is named tailer, it is created by consumerTailer = queue.createTailer("myConsumer");
I need to get the unread msg count, I used the following way, but it seems that result of queue.lastIndex() change very largely only when one msg is appended to queue
` public long getNumberOfUnconsumedMessages() {
// 获取当前 tailer 的索引
long currentIndex = consumerTailer.index();
long lastIndex = queue.lastIndex();
long unReadCount = 0l;
if (lastIndex != -1L) {
//This will return the index of the last data present in the queue (or -1 for an empty queue).
// 计算未消费消息的数量
unReadCount = lastIndex - currentIndex;
}
log.info("unReadCount:{}, currentIndex:{}, lastIndex:{}", unReadCount, currentIndex, lastIndex);
return unReadCount;
}`
log issue:
2024-03-06 16:04:44,662 INFO [cellconn-main-1] a.m.o.c.mq.MessageConsumer.getNumberOfUnconsumedMessages: unReadCount:-1, currentIndex:84984517885968, lastIndex:84984517885967 I only add one msg, but the lastIndex is changed very largely. 2024-03-06 16:04:54,756 INFO [cellconn-main-1] a.m.o.c.mq.MessageConsumer.getNumberOfUnconsumedMessages: unReadCount:4294967280, currentIndex:84984517885968, lastIndex:84988812853248
do we have some ways to get the unread msg count correctly? Thank you!
@tgd
Hi @useryq8
I only add one msg, but the lastIndex is changed very largely
Can you share a unit test that reproduces this?
We do review issues here but they are assigned lower priority than our commercial support offerings. For commercial support please contact https://chronicle.software/contact-us/