Search code examples
chroniclechronicle-queue

Save consumer/tailer read offset for ChronicleQueue


I am exploring ChronicleQueue to save events generated in one of my application.I would like to publish the saved events to a different system in its original order of occurrence after some processing.I have multiple instances of my application and each of the instance could run a single threaded appender to append events to ChronicleQueue.Although ordering across instances is a necessity,I would like to understand these 2 questions.

1)How would the index of the read index for my events be saved so that I don't end up reading and publishing the same message from chronicle queue multiple times.

In the below code(picked from the example in github) the index is saved till we reach the end of the queue while we restarted the application.The moment we reach the end of the queue,we end up reading all the messages again from the start.I want to make sure for a particular consumer identified by a tailer Id, the messages are read only once.Do i need to save the read index in another queue and use that to achieve what I need here.


String file = "myPath";
try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(file).build()) {
  for(int i = 0 ;i<10;i++){
    cq.acquireAppender().writeText("test"+i);
  }
}


try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(file).build()) {
    ExcerptTailer atailer = cq.createTailer("a");
    System.out.println(atailer.readText());
    System.out.println(atailer.readText());
    System.out.println(atailer.readText()); 
}

2)Also need some suggestion if there is a way to preserve ordering of events across instances.


Solution

  • Using a named tailer should ensure that the tailer only reads a message once. If you have an example where this doesn't happen can you create a test to reproduce it?

    The order of entries in a queue are fixed when writing and all tailer see the same messages in the same order, there isn't any option.