Copy data from one Chronicle to another

235 views Asked by At

For the concept of taking back up , i need to copy data from one chronicle queue to another .

Would it be safe to do a directly copy the whole Bytes object from wire of one queue into another ?

something like

documentContext().wire().bytes().read(byte_buffer)

and then wrapping this byte_buffer into byte_store and writing as

documentContext().wire().bytes().write(byte_Store).

The reason i'm doing it is avoid any conversion back and forth into custom objects?

1

There are 1 answers

1
Peter Lawrey On

You can, but a simpler approach is to copy directly from one to the other.

ChronicleQueue inQ = SingleChronicleQueueBuilder.binary("in").build();
ExcerptTailer tailer = inQ.createTailer();
ChronicleQueue outQ = SingleChronicleQueueBuilder.binary("out").build();
ExcerptAppender appender = outQ.acquireAppender();

while(true) {
    try (DocumentContext inDC = tailer.readingDocument()) {
        if (!inDC.isPresent()) {
            // not message available
            break; // or pause or do something else.
        }
        try (DocumentContext outDC = appender.writingDocument()) {
            outDC.wire().write(inDC.wire().bytes());
        }
    }
}

}