Search code examples
chroniclechronicle-queue

Chroncile Queue tailer adds additional bytes (0x008F) for some buffers. How to determine which buffers have this padding?


We are marshalling XML data as string and converting it into bytes with getBytes(StandardCharsets.UTF_8) and writing them to chronicle queue:

try (DocumentContext dc = appender.writingDocument()) {
    Wire wire = dc.wire();
    Bytes bytes = wire.bytes();
    bytes.write(message);
}

and reading like this:

DocumentContext dc = tailer.readingDocument();
if (dc.isPresent()) {
    Bytes bytes = dc.wire().bytes();
    int length = bytes.length();
    byte[] output = new byte[length];
    bytes.read(output);
    return output;
} 

When we read buffers back, most of buffer sizes match but for some buffers like 1 in 100, we get additional bytes ( 1/2/3 bytes of 0x008F). We couldn't determine which buffers have this padding and couldn't really unmarshal the buffer because of this padding. Couldn't understand why some buffers have these extra bytes?


Solution

  • If you want to write/read XML data you are better off letting the Queue encode and decode this string as this saves creating a byte[]

    try (DocumentContext dc = appender.writingDocument()) {
        dc.wire().getValueOut().text(text);
    }
    

    and

    // can be reused.
    StringBuilder sb = new StringBuilder();
    
    try (DocumentContext dc = tailer.readingDocument()) {
        if (dc.isPresent()) {
            dc.wire().text(sb);
            String text = sb.toString();
            process(text);
        }
    

    }

    NOTE: From version 5.16.14 of Queue you will be able to use writeText/readText

    appender.writeText(text);
    

    and

    String s = tailer.readText();