这是Chronicle的版本:
<groupId>net.openhft</groupId>
<artifactId>chronicle-queue</artifactId>
<version>5.21.93</version>这是我如何使用附加器编写的:
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或他们的文档?)
发布于 2021-11-18 08:28:30
尝试以下操作:您可以在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);
}
}
}发布于 2021-11-18 09:02:01
https://stackoverflow.com/questions/70001829
复制相似问题