chronicle vs chronicle-queue package

痞子三分冷 提交于 2019-12-11 07:47:45

问题


I'm just getting started with chronicle queue - however I'm a bit confused on which API to use for reading/writing to the queue. Specifically chronicle-queue-5 vs chronicle-3.5.*

I've gone through this link which basically uses chronicle-queue API , but there are others like this which uses chronicle.

What is the difference between these 2 below?

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

vs

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 " );
 }

The Javadoc documentation for ChronicleQueue and Chronicle seems very similar


回答1:


They are both writing a message to a chronicle queue. I belive this

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

can now be written in chronicle queue 5 like this

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

Or if you wanted to store key:value data, like this

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");
}

you can use

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

to see how the data is stored, for example

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


来源:https://stackoverflow.com/questions/57498047/chronicle-vs-chronicle-queue-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!