首页 / JAVA / 阅读后未删除Java编年史消息
阅读后未删除Java编年史消息
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了阅读后未删除Java编年史消息,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1979字,纯文字阅读大概需要3分钟。
内容图文
![阅读后未删除Java编年史消息](/upload/InfoBanner/zyjiaocheng/664/159c001aee194137aa8e68e8a09f657f.jpg)
我正在尝试使用Java Chronicle 1.9.2编写/读取消息.我知道可以使用更新的版本,但是在我花更多时间之前,几乎没有疑问.
阅读纪事摘录后,我需要删除邮件.
因此,如果我的读者重新开始,它就不会回到开始.
同样的消息对我来说一经阅读就没有用了,所以想删除它.
有选择的办法吗?我正在尝试遵循代码,并且每次启动阅读器时,我都会再次收到所有消息.
此外,还有一个选项可以设置“生存时间”消息,以便在一定时间后自动将其删除.
作家-
String tempPath = System.getProperty("java.io.tmpdir");
String basePrefix = tempPath + "chronicle";
System.out.println("base prefix: " + basePrefix);
Chronicle chr = new IndexedChronicle(basePrefix);
final Excerpt excerpt = chr.createExcerpt();
excerpt.startExcerpt(this.getmsgtext().length() + 4);
excerpt.writeBytes(this.getmsgtext());
excerpt.finish();
chr.close();
读者-
String tempPath = System.getProperty("java.io.tmpdir");
String basePrefix = tempPath + "chronicle";
System.out.println("base prefix: " + basePrefix);
Chronicle chr = new IndexedChronicle(basePrefix);
final Excerpt excerpt = chr.createExcerpt();
while (excerpt.nextIndex()) {
System.out.println("Read string from chronicle: " + excerpt.readByteString());
}
chr.close();
解决方法:
I need to have the message removed once i read the Excerpt from the Chronicle.
删除它们的唯一方法是滚动文件.您可以使用IndexedChronicle或使用VanillaChronicle或当前的SingleChronicleQueue自己完成此操作
So if my reader starts again it doesn’t go back to the beginning. Also message is of no use to me once i read it so want to remove it.
标准做法是将您的结果(包括源ID)写入“纪事”.这样,您始终知道哪些消息已成功处理.例如如果发生崩溃,您可能已经阅读了消息,但未处理.
i am trying following code and every time i start reader, i get all the messages again.
这是默认情况下设计的.您如何跟踪正确处理了哪些消息取决于您. (尽管我们建议将其记录在另一个队列中,并阅读最后一条消息以找到该索引)
Is there an option to put a Time to Live on message so it is automatically removed after certain time period.
您可以为每个消息添加时间戳,并忽略旧消息.
Chronicle Queue v4.1.0是最新版本.
内容总结
以上是互联网集市为您收集整理的阅读后未删除Java编年史消息全部内容,希望文章能够帮你解决阅读后未删除Java编年史消息所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。