我刚刚开始记录编年史队列-但是,对于使用哪个API来读取/写入队列,我有些困惑。特别是chronicle-queue-5chronicle-3.5.*

我已经看过了这个link,它基本上使用编年史API,但是还有其他类似this的历史书。

以下这2个有什么区别?

 Chronicle chronicle =  ChronicleQueueBuilder.indexed(_location).build();
 ExcerptAppender appender = chronicle.createAppender();
 appender.startExcerpt();
 appender.writeUTF("Hello World");




ChronicleQueue queue = ChronicleQueue.singleBuilder(_location).build();
final net.openhft.chronicle.queue.ExcerptAppender appender = queue.acquireAppender();
 try (DocumentContext dc = appender.writingDocument())
 {
     dc.wire().write("hello").text("world " );
 }


ChronicleQueue的Javadoc文档

Chronicle看起来非常相似

最佳答案

他们俩都在将消息写入编年史队列。我相信这个

Chronicle chronicle =  ChronicleQueueBuilder.indexed(_location).build();
ExcerptAppender appender = chronicle.createAppender();
appender.startExcerpt();
appender.writeUTF("Hello World");


现在可以像这样写在编年史队列5中

try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary("temp-dir").build()) {
   final ExcerptAppender appender = queue.acquireAppender();
   appender.writeText("Hello World");
}


或者,如果您想存储keyvalue数据,像这样

try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary("temp-dir-2").build()) {
  final ExcerptAppender appender = queue.acquireAppender();
  try (DocumentContext dc = appender.writingDocument()) {
    dc.wire().write("hello").text("world");
  }
  DumpQueueMain.dump("temp-dir-2");
}


您可以使用

DumpQueueMain.dump("temp-dir-2");


例如查看数据的存储方式

# position: 131360, header: 2
--- !!data #binary
hello: world

关于java - 编年史vs编年史队列包,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57498047/

10-11 10:54