如何在使用 writingDocument 时从 Chronicle Queue 中读取?

How to read from Chronicle Queue while using writingDocument?

这是 Chronicle Queue 的版本:

<groupId>net.openhft</groupId>
<artifactId>chronicle-queue</artifactId>
<version>5.21.93</version>

这是我使用 appender 编写的方式:

        String basePath = OS.userDir() + "\start";
        ChronicleQueue queue = SingleChronicleQueueBuilder.single(basePath).build();

        ExcerptAppender appender = queue.acquireAppender();
        DocumentContext documentContext = null;
        int i = 0;
        try {
            documentContext = appender.writingDocument();
            for (int j=0;j<1000;j++) {
                     documentContext.wire().write().text("text :: "+i++);
            }
        } finally {
            documentContext.close();
        }

我是这样读的:

        ExcerptTailer b = queue.createTailer("b");

        String out = "";
        while ((out=b.readText())!=null){
            System.out.println(out);
        }

这是例外情况:

Exception in thread "main" net.openhft.chronicle.bytes.UTFDataFormatRuntimeException: 1010d
00010080                                         00 00 00               ···
........
00010100 00 00 00 00 00 00 00 00  5a 32 00 00 c0 e9 74 65 ········ Z2····te
00010110 78 74 20 3a 3a 20 30 c0  e9 74 65 78 74 20 3a 3a xt :: 0· ·text ::
00010120 20 31 c0 e9 74 65 78 74  20 3a 3a 20 32 c0 e9 74  1··text  :: 2··t
00010130 65 78 74 20 3a 3a 20 33  c0 e9 74 65 78 74 20 3a ext :: 3 ··text :
00010140 3a 20 34 c0 e9 74 65 78  74 20 3a 3a 20 35 c0 e9 : 4··tex t :: 5··
00010150 74 65 78 74 20                                   text             
... truncated
    at net.openhft.chronicle.bytes.internal.BytesInternal.parseUtf8_SB1(BytesInternal.java:503)
    at net.openhft.chronicle.bytes.internal.BytesInternal.parseUtf8(BytesInternal.java:221)
    at net.openhft.chronicle.bytes.StreamingDataInput.parseUtf8(StreamingDataInput.java:553)
    at net.openhft.chronicle.wire.BinaryWire.getStringBuilder(BinaryWire.java:775)
    at net.openhft.chronicle.wire.BinaryWire.readText(BinaryWire.java:1264)
    at net.openhft.chronicle.wire.BinaryWire.readText(BinaryWire.java:1270)
    at net.openhft.chronicle.wire.BinaryWire$BinaryValueIn.textTo(BinaryWire.java:2326)
    at net.openhft.chronicle.wire.ValueIn.text(ValueIn.java:61)
    at net.openhft.chronicle.wire.MarshallableIn.readText(MarshallableIn.java:103)
    at com.cq.test.Test.main(Test.java:48)
Caused by: net.openhft.chronicle.bytes.UTFDataFormatRuntimeException: malformed input around byte 2 was 116 101
    at net.openhft.chronicle.bytes.internal.BytesInternal.parseUtf82(BytesInternal.java:630)
    at net.openhft.chronicle.bytes.internal.BytesInternal.parseUtf8_SB1(BytesInternal.java:500)
    ... 9 more

Process finished with exit code 1

我的问题是我如何读取数据以及我在哪里可以获得这种用法(github 或者他们的文档在什么地方?)

尝试以下操作: 您可以在 https://github.com/OpenHFT/Chronicle-Queue

中找到文档
 public static void main(String[] args) {
    String basePath = OS.userDir() + "/start";
    ChronicleQueue queue = SingleChronicleQueueBuilder.single(basePath).build();

    ExcerptAppender appender = queue.acquireAppender();
    DocumentContext documentContext = null;
    int i = 0;
    try {
        documentContext = appender.writingDocument();
        for (int j=0;j<10;j++) {
            documentContext.wire().write("No "+i).text(" text :: "+i++);

        }
    }
    finally {
        documentContext.close();
    }

    ExcerptTailer b = queue.createTailer("b");

        int k=0;
        try (final DocumentContext dc = b.readingDocument()) {
            if (!dc.isPresent())
                return;
            for (i=0;i<10 ;i++ ) {
            final String output = dc.wire().read("No "+k++).text();

                System.out.println(output);

        }
    }

}

用户指南在这里: https://github.com/OpenHFT/Chronicle-Queue#user-guide

写入队列: https://github.com/OpenHFT/Chronicle-Queue#writing-to-a-queue-using-an-appender

从队列中读取: https://github.com/OpenHFT/Chronicle-Queue#reading-from-a-queue-using-a-tailer