我正在尝试使用 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();