Search code examples
chronicle-queue

ChronicleQueue - how to read custom object from tailer


I am very new to ChronicleQueue and I am unable to find a straight forward example of how can I read back my custom object from a tailer.

public class MyData extends AbstractMarshallable

I have my class containing some strings and numbers, I am able to write to queue using appender, but there is no straight forward api to call. how can i get a object of MyData from tailer.readDocument api?


Solution

  • Try with below code:

    final DocumentContext context = queue.createTailer().readingDocument();
    final MyData container = new MyData();
    if (context.isPresent()) {
        context.wire().getValueIn().marshallable(container);
    }
    

    this assumes that appending is performed in the following manner:

    try (DocumentContext ctx = appender.writingDocument()) {
        ctx.wire().getValueOut().marshallable(myData);
    }