Search code examples
javachroniclechronicle-queue

chronicle vs chronicle-queue package


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


Solution

  • 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