Quick Start

Getting Started

This section helps you get started with Chronicle Queue in a few minutes. The process can be summed up in five steps:

The provided guide does not intend to be an exhaustive explanation of these steps but rather provide enough information to get you up and running quickly. Hence, most of the topics are explained in greater depth throughout the Chronicle Queue documentation.


Before starting with the setup, make sure your development environment meets the following requirements:

  • Maven 3.6.x or later
  • Java 8 update 180+ or later
  • Access to the internet to allow Maven or Gradle to download the JARs needed

Installing Chronicle Queue

The installation is performed by notifying your build tool that the Chronicle Queue dependency is required to compile your source code. Below are instructions for installation using Maven or Gradle.

You will need to look up the latest version of Chronicle Queue on Maven Central.


Install Chronicle Queue with Maven by adding the following code in the project’s pom.xml-file:

  <version><!--Latest version--></version>


Install Chronicle Queue with Gradle by adding the following code in the project’s build.gradle-file:

dependencies {
  implementation 'net.openhft:chronicle-queue:Latest-version' 

Hello World with Chronicle Queue

Now that the installation is complete it is time to create a first queue and try appending and reading messages from it.

Creating a New Queue

A new Chronicle Queue is obtained from a builder by passing the field singleBuilder the path where the queue is to be stored. The example below creates an IndexedChronicle which creates two RandomAccessFiles; one for indexes, and one for data having names relatively:

String basePath = OS.getTarget() + "/getting-started"
ChronicleQueue queue = ChronicleQueue.singleBuilder(basePath).build()

The queue files will reside in the directory getting-started and files are named with the current date on the following format:


Writing to a Queue

Messages are written, or appended, to a queue using an appender. The appender writes messages to the end of the queue only, there is no way to insert messages at a specific location.

Here is how you can append a simple text message containing the text "Hello World!":

ExcerptAppender appender = queue.acquireAppender(); 
appender.writeText("Hello World!");

Reading from a Queue

Reading a from a queue is easiest done using a tailer, namely ExcerptTailer. The term tailing stems from reading from the queue’s tail, i.e. the end of the queue. However, you are not limited to only read from the end of the queue using the tailer.

Here is how it is used to read the "Hello World" message that was just written to the queue:

ExcerptTailer tailer = queue.createTailer(); 
assertEquals("Hello World!", tailer.readText()); 

You can also dump the raw contents of the queue to the console using the method dump():


Cleaning Up

Chronicle Queue stores its data off-heap, therefore it is recommended that you call .close() once you have finished working with Chronicle Queue to free up resources. No data will be lost when closing the queue. This procedure only cleans up resources that were used at runtime.


Putting it All Together

Putting these instructions together, the application looks as follows:

String basePath = OS.getTarget() + "/getting-started"
try (ChronicleQueue queue = ChronicleQueue.singleBuilder(basePath).build()) {
    ExcerptAppender appender = queue.acquireAppender();

    ExcerptTailer tailer = queue.createTailer();
    assertEquals("TestMessage", tailer.readText());