ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

阅读后未删除Java编年史消息

2019-11-19 00:03:43  阅读:267  来源: 互联网

标签:messaging java chronicle


我正在尝试使用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是最新版本.

标签:messaging,java,chronicle
来源: https://codeday.me/bug/20191118/2031857.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有