### Starting Chronicle Queue Replication Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/replication/pages/replication.adoc Instantiates and starts the replication process for a given host using a configuration and host ID. ```java try (ReplicatedQueue repl = new ReplicatedQueue(config(), hostId)) { repl.startReplication(); ... } ``` -------------------------------- ### New Order Binary Data Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/BigDataAndChronicleQueue.adoc Example of binary data for a new order, including symbol, side, limitPrice, and quantity. ```yaml --- !!data #binary newOrder: !Order { symbol: Symbol2, side: Sell, limitPrice: 2.999, quantity: 10000000.0 } ``` -------------------------------- ### Create and Execute Pretoucher Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Instantiate a Pretoucher for a given Chronicle Queue and start its execution. Ensure proper resource management with try-with-resources. ```java // Creates the queue q1 (or q1 is a queue that already exists) try(final SingleChronicleQueue q1 = SingleChronicleQueueBuilder.binary("queue-storage-path").build(); final Pretoucher pretouch = PretouchUtil.INSTANCE.createPretoucher(q1)){ try { pretouch.execute(); } catch (InvalidEventHandlerException e) { throw Jvm.rethrow(e); } } ``` -------------------------------- ### Binary Data Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/BigDataAndChronicleQueue.adoc Example of binary data structure with symbol, side, limitPrice, and quantity. ```yaml --- !!data #binary symbol: Symbol side: Buy limitPrice: 1.2345 quantity: 1000000.0 ``` -------------------------------- ### Basic Asynchronous Write Setup Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/async-mode/pages/async_mode.adoc Demonstrates setting up a Chronicle Queue with asynchronous write buffering. Ensure the buffer capacity and write mode are configured. ```java try (ChronicleQueue queue = SingleChronicleQueueBuilder .binary(path) .bufferCapacity(1 << 20) .writeBufferMode(BufferMode.Asynchronous) .build()) { ExcerptAppender appender = queue.createAppender(); ... ExcerptTailer tailer = queue.createTailer(); ... } ``` -------------------------------- ### Run the bridge process with Maven Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/demos/pages/message-history.adoc Start the bridge process first to ensure it's warm before publishing messages. ```sh mvn exec:java@BridgeMain ``` -------------------------------- ### Run Gateway Service Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/Channel-Pipe-Benchmarks.adoc Command to start the gateway service for Chronicle-Channel. ```bash mvn exec:java@Gateway ``` -------------------------------- ### Start Reading from a Queue Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Initializes a Chronicle Queue and creates an ExcerptTailer to read messages. ```java try (ChronicleQueue queue = ChronicleQueue.singleBuilder(path + "/trades").build()) { final ExcerptTailer tailer = queue.createTailer(); } ``` -------------------------------- ### Restartable Tailer Example Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Demonstrates how named tailers ('a' and 'b') maintain their read positions across application restarts. The index is preserved within the queue itself. ```java try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) { ExcerptTailer atailer = cq.createTailer("a"); assertEquals("test 0", atailer.readText()); assertEquals("test 1", atailer.readText()); assertEquals("test 2", atailer.readText()); // <1> ExcerptTailer btailer = cq.createTailer("b"); assertEquals("test 0", btailer.readText()); // <3> } try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) { ExcerptTailer atailer = cq.createTailer("a"); assertEquals("test 3", atailer.readText()); // <2> assertEquals("test 4", atailer.readText()); assertEquals("test 5", atailer.readText()); ExcerptTailer btailer = cq.createTailer("b"); assertEquals("test 1", btailer.readText()); // <4> } ``` -------------------------------- ### Example Dumped Queue Data (YAML) Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc This is an example of the output generated when dumping a Chronicle Queue file using DumpMain. It shows the metadata and structure of the queue. ```yaml !!meta-data #binary header: !SCQStore { wireType: !WireType BINARY, writePosition: 0, roll: !SCQSRoll { length: !int 3600000, format: yyyyMMdd-HH, epoch: !int 3600000 }, indexing: !SCQSIndexing { indexCount: !short 4096, indexSpacing: 4, index2Index: 0, lastIndex: 0 }, lastAcknowledgedIndexReplicated: -1, recovery: !TimedStoreRecovery { timeStamp: 0 } } ... ``` -------------------------------- ### Restartable Tailers Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/tailing/pages/tailing.adoc Demonstrates the use of named tailers which can resume reading from their last position after an application restart. The index is preserved across restarts. ```java try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) {\n ExcerptTailer atailer = cq.createTailer("a");\n assertEquals("test 0", atailer.readText());\n assertEquals("test 1", atailer.readText());\n assertEquals("test 2", atailer.readText()); #<1>\n\n ExcerptTailer btailer = cq.createTailer("b");\n assertEquals("test 0", btailer.readText()); #<3>\n}\n\ntry (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) {\n ExcerptTailer atailer = cq.createTailer("a");\n assertEquals("test 3", atailer.readText()); #<2>\n assertEquals("test 4", atailer.readText());\n assertEquals("test 5", atailer.readText());\n\n ExcerptTailer btailer = cq.createTailer("b");\n assertEquals("test 1", btailer.readText()); #<4>\n} ``` -------------------------------- ### Complete Chronicle Queue Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/getting-started/pages/quick-start.adoc This Java code demonstrates the complete cycle of creating a queue, appending a message, reading it back, and closing the queue using a try-with-resources statement for automatic cleanup. ```java String basePath = OS.getTarget() + "/getting-started" try (ChronicleQueue queue = ChronicleQueue.singleBuilder(basePath).build()) { ExcerptAppender appender = queue.createAppender(); appender.writeText("TestMessage"); ExcerptTailer tailer = queue.createTailer(); assertEquals("TestMessage", tailer.readText()); queue.close(); } ``` -------------------------------- ### Meta-data Header Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/BigDataAndChronicleQueue.adoc Example of meta-data header structure in YAML, including wireType, writePosition, roll, and indexing details. ```yaml --- --- !!meta-data #binary # <1> header: !SCQStore { # <2> wireType: !WireType BINARY, writePosition: 413, # <3> roll: !SCQSRoll { # <4> length: !int 86400000, format: yyyyMMdd, epoch: 0 }, indexing: !SCQSIndexing { # <5> indexCount: !short 16384, indexSpacing: 16, index2Index: 0, lastIndex: 0 }, lastAcknowledgedIndexReplicated: 0 # <6> } ``` -------------------------------- ### Example: Write Messages and Read from Index Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/queue-operations/pages/indexing.adoc Demonstrates writing multiple messages to a queue, calculating an index for a specific message (the 5th), moving a tailer to that index, and reading the message. This showcases random access reads using indexes. ```java try (final ChronicleQueue queue = singleBuilder("queue").build()) { final ExcerptAppender appender = queue.createAppender(); for (int i = 0; i < 10; i++) { appender.writeText("message " + i); } int cycle; final ExcerptTailer tailer = queue.createTailer(); try (DocumentContext documentContext = tailer.readingDocument()) { cycle = queue.rollCycle().toCycle(documentContext.index()); } long index = queue.rollCycle().toIndex(cycle, 5); tailer.moveToIndex(index); System.out.println(tailer.readText()); } ``` -------------------------------- ### Example Dumped Queue Data (YAML) Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/command-line/pages/command_line_tools.adoc This is an example of the output generated when dumping a Chronicle Queue file. It shows metadata such as wire type, roll settings, and indexing configuration. ```yaml !!meta-data #binary header: !SCQStore { wireType: !WireType BINARY, writePosition: 0, roll: !SCQSRoll { length: !int 3600000, format: yyyyMMdd-HH, epoch: !int 3600000 }, indexing: !SCQSIndexing { indexCount: !short 4096, indexSpacing: 4, index2Index: 0, lastIndex: 0 }, lastAcknowledgedIndexReplicated: -1, recovery: !TimedStoreRecovery { timeStamp: 0 } } ... ``` -------------------------------- ### Install Chronicle Queue with Gradle Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/getting-started/pages/quick-start.adoc Add this implementation to your project's build.gradle file to include Chronicle Queue. Replace '' with the actual latest version from Maven Central. ```gradle dependencies { implementation 'net.openhft:chronicle-queue:' } ``` -------------------------------- ### Restartable Tailers Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/queue-operations/pages/tailing.adoc Demonstrates how named tailers ('a' and 'b') maintain their read position across application restarts. The index is preserved and reading continues from the last acknowledged message. ```java try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) { ExcerptTailer atailer = cq.createTailer("a"); assertEquals("test 0", atailer.readText()); assertEquals("test 1", atailer.readText()); assertEquals("test 2", atailer.readText()); #<1> ExcerptTailer btailer = cq.createTailer("b"); assertEquals("test 0", btailer.readText()); #<3> } try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) { ExcerptTailer atailer = cq.createTailer("a"); assertEquals("test 3", atailer.readText()); #<2> assertEquals("test 4", atailer.readText()); assertEquals("test 5", atailer.readText()); ExcerptTailer btailer = cq.createTailer("b"); assertEquals("test 1", btailer.readText()); #<4> } ``` -------------------------------- ### Example Downstream Message with Timings Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Illustrates the structure of a downstream message that includes timing information, showing source IDs and timestamps for message events. ```Yaml --- !!data #binary history: { sources: [ 1, 0x426700000000 # <4> ] timings: [ 1394278797664704, # <1> 1394278822632044, # <2> 1394278824073475 # <3> ] } onTopOfBookPrice: { symbol: EURUSD1, timestamp: 123456789000, buyPrice: NaN, buyQuantity: 0, sellPrice: 1.1172, sellQuantity: 2000000.0 } ``` -------------------------------- ### MethodWriter Example for Chronicle Queue Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/utilities.adoc Example of building a MethodWriter to write events to a Chronicle Queue. This is relevant when using the `-r` flag with ChronicleReader. ```java MethodWriterBuilder methodWriterBuilder = excerptAppender.methodWriterBuilder(StringEvents.class); StringEvents events = methodWriterBuilder.build(); events.say("hello"); ``` -------------------------------- ### Write and Read Specific Message Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Example of writing 10 messages to a queue and then reading the 5th message. It demonstrates obtaining the current cycle and using a tailer to read a specific document context. ```java @Test public void read5thMessageTest() { try (final ChronicleQueue queue = singleBuilder(getTmpDir()).build()) { final ExcerptAppender appender = queue.createAppender(); int i = 0; for (int j = 0; j < 10; j++) { try (DocumentContext dc = appender.writingDocument()) { dc.wire().write("hello").text("world " + (i++)); long indexWritten = dc.index(); } } // Get the current cycle int cycle; final ExcerptTailer tailer = queue.createTailer(); try (DocumentContext documentContext = tailer.readingDocument()) { long index = documentContext.index(); cycle = queue.rollCycle().toCycle(index); } ``` -------------------------------- ### Chronicle Queue Binary Format Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/tailing/pages/tailing.adoc This is a representation of the binary data stored in a Chronicle Queue file (`.cq4`). It is typically difficult to read directly and is better viewed using dump tools. ```text \@πheader∂SCQStoreÇE»wireType∂WireTypeÊBINARYÕwritePositionèèèè߃roll∂SCQSRollÇ*∆length¶ÄÓ6∆format\nÎyyyyMMdd-HH≈epoch¶ÄÓ6»indexing∂\fSCQSIndexingÇN\u00A0indexCount•ÃindexSpacingÀindex2Indexéß…lastIndexé\nßfllastAcknowledgedIndexReplicatedéߡˇˇˇˇˇˇˇ»recovery∂TimedStoreRecoveryÇ…timeStampèèèß\n\n\n\n\n ``` -------------------------------- ### Chronicle Queue Topic Directory Structure Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Shows an example of how topics are organized within a Chronicle Queue, with each day's data in a separate .cq4 file. ```text mytopic/ 20160710.cq4 20160711.cq4 20160712.cq4 20160713.cq4 ``` -------------------------------- ### Example decoded message output Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/demos/pages/message-history.adoc This output shows a decoded message including VanillaMessageHistory details and raw byte representation. ```text VanillaMessageHistory{sources: [1=0x474c00000000,2=0x474c00000000] timings: [613056255568600,613056286396600,613056336886100,618767110988300] addSourceDetails=true} - 1, source: publisher, ts: 2019-12-22T14:37:19.426755 84 00 00 00 # msg-length b9 07 68 69 73 74 6f 72 79 # history 82 5b 00 00 00 # VanillaMessageHistory c7 73 6f 75 72 63 65 73 82 14 00 00 00 # sources 01 af 00 00 00 00 4c 47 00 00 # source id & index 02 af 00 00 00 00 4c 47 00 00 # source id & index c7 74 69 6d 69 6e 67 73 82 2d 00 00 00 # timings a7 d8 2a 57 48 92 2d 02 00 # timing in nanos a7 b8 90 2d 4a 92 2d 02 00 # timing in nanos a7 54 f9 2f 4d 92 2d 02 00 # timing in nanos a7 0c 62 d9 f1 c3 32 02 00 a7 54 d5 d3 36 c4 32 # timing in nanos 02 00 ba 01 # eventOne 82 14 00 00 00 # EventOne 09 70 75 62 6c 69 73 68 65 72 # eventSource c3 68 1e d9 4b 9a 05 00 # eventTimeStamp 80 00 # text ``` -------------------------------- ### Run Chronicle Reader Utility with Maven Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/utilities.adoc Use this command to run the Chronicle Reader utility via Maven. Ensure you have Maven installed and configured. ```java $ mvn exec:java -Dexec.mainClass="net.openhft.chronicle.queue.ChronicleReaderMain" ``` -------------------------------- ### Install Chronicle Queue with Maven Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/getting-started/pages/quick-start.adoc Add this dependency to your project's pom.xml file to include Chronicle Queue. Replace '' with the actual latest version from Maven Central. ```xml net.openhft chronicle-queue ``` -------------------------------- ### Reading Raw Data as Primitives and Strings Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Reads raw data from the queue as primitive types and strings using the `readBytes` method. This example demonstrates reading a byte, an integer, a long, and a UTF-8 encoded string. ```java assertTrue(tailer.readBytes(in -> { int code = in.readByte(); int num = in.readInt(); long num2 = in.readLong(); String text = in.readUtf8(); assertEquals("Hello World", text); // do something with values })); ``` -------------------------------- ### Build the code with Maven Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/demos/pages/message-history.adoc Use this command to package the demo code before running. ```sh mvn package ``` -------------------------------- ### Example CHRM output Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/demos/pages/message-history.adoc This is an example of the output generated by the Chronicle History Reader Main tool, showing timings in microseconds. ```text Timings below in MICROSECONDS sourceId 1 startTo1 count: 100001 100001 50: 1 1 90: 3 2 99: 31 40 99.9: 62 80 99.99: 108 120 ``` -------------------------------- ### Create Chronicle Queue in Temporary Directory Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/How_it_works.adoc Shows how to create a Chronicle Queue instance using a temporary directory as its storage path. ```java File tmpPath = Files.createTempDirectory("SimpleChronicle").toFile(); SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(tmpPath).build(); ``` -------------------------------- ### Write Document using Try-with-Resources Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/FAQ.adoc Shows how to write a document to a Chronicle Queue using a try-with-resources block for proper resource management. ```java try (DocumentContext dc = wire.writingDocument(false)) { dc.wire().writeEventName("msg").text("Hello world"); } ``` -------------------------------- ### YAML Payload Example 1 Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc A simple YAML payload for a DTO object. ```yaml { age: 19, name: Henry } ``` -------------------------------- ### YAML Payload Example 2 Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc A YAML payload with a specific DTO type annotation. ```yaml !x.y.z.DTO { age: 42, name: Percy } ``` -------------------------------- ### Invoke DumpMain using Maven Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/command-line/pages/command_line_tools.adoc Demonstrates how to invoke the DumpMain command-line tool using Maven to display records from a queue. ```shell script $ mvn exec:java -Dexec.mainClass="net.openhft.chronicle.queue.main.DumpMain" -Dexec.args="myqueue" ``` -------------------------------- ### Create Chronicle Queue Instance Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Demonstrates how to create an instance of Chronicle Queue using the SingleChronicleQueueBuilder. This sets up the base path for queue files. ```java String basePath = OS.getTarget() + "/getting-started" ChronicleQueue queue = SingleChronicleQueueBuilder.single(basePath).build(); ``` -------------------------------- ### Custom Object Serialization Example Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/How_it_works.adoc Defines a custom object 'MyObject' that implements Marshallable, suitable for serialization and deserialization with Chronicle Wire. ```java package net.openhft.chronicle.queue; import net.openhft.chronicle.queue.impl.single.SingleChronicleQueue; import net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder; import net.openhft.chronicle.wire.Marshallable; import java.io.IOException; import java.nio.file.Files; public class Example { static class MyObject implements Marshallable { String name; int age; @Override public String toString() { return Marshallable.$toString(this); } } ``` -------------------------------- ### Creating and Using Method Writer Proxy Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/appending/pages/appending.adoc Demonstrates how to create a method writer proxy for an asynchronous interface and send messages to the queue. The proxy allows calling interface methods directly to write data. ```java SingleChronicleQueue queue1 = ChronicleQueue.singleBuilder(path).build(); MessageListener writer1 = queue1.createAppender().methodWriter(MessageListener.class); // call method on the interface to send messages writer1.method1(new Message1("hello")); writer1.method2(new Message2(234)); ``` -------------------------------- ### Append a Text Message to the Queue Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/getting-started/pages/quick-start.adoc Use an ExcerptAppender to write messages to the end of a Chronicle Queue. This example appends the text 'Hello World!'. ```java ExcerptAppender appender = queue.createAppender(); appender.writeText("Hello World!"); ``` -------------------------------- ### Identify removable roll file candidates Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/managing_roll_files_directly.adoc Use `FileUtil.removableRollFileCandidates` to get a list of files that are candidates for removal. This method is only supported on Linux/BSD systems. ```java List candidates = FileUtil.removableRollFileCandidates(dir).collect(toList()); ``` -------------------------------- ### Read a Text Message from the Queue Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/getting-started/pages/quick-start.adoc Use an ExcerptTailer to read messages from a Chronicle Queue. This example reads the 'Hello World!' message previously written. ```java ExcerptTailer tailer = queue.createTailer(); assertEquals("Hello World!", tailer.readText()); ``` -------------------------------- ### Create, Write, and Read from Chronicle Queue Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/How_it_works.adoc Demonstrates the basic workflow of creating a Chronicle Queue, appending a text message, and then reading it back. The queue is persisted to the working directory. ```java // will write the .cq4 file to working directory try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder().path(".").build(); ExcerptAppender appender = queue.createAppender(); ExcerptTailer tailer = queue.createTailer()) { // write 'hello world' to the queue appender.writeText("hello word"); // read 'hello world' from the queue System.out.println(tailer.readText()); } ``` -------------------------------- ### Java 7 Try-with-Resources for Appender Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/MigratingToV4.adoc Demonstrates writing and reading documents using a try-with-resources block with an ExcerptAppender. ```java // Writing Java 7 style without a lambda try (DocumentContext dc = appender.writingDocument()) { Bytes bytes = dc.wire().bytes(); // write to the bytes } // Reading Java 7 style without a lambda try (DocumentContext dc = appender.readingDocument()) { Bytes bytes = dc.wire().bytes(); // read from the bytes } ``` -------------------------------- ### Display Chronicle Reader Help Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/utilities.adoc Display the help documentation for the Chronicle Reader utility. Use the `-h` argument. ```java $ mvn exec:java -Dexec.mainClass="net.openhft.chronicle.queue.ChronicleReaderMain" -Dexec.args="-h" ``` -------------------------------- ### YAML Payload for DTO Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/appending/pages/appending.adoc Provides a YAML representation of a DTO object, suitable for use with ChronicleWriterMain. This example shows a simple key-value structure for the DTO fields. ```yaml { age: 19, name: Henry } ``` -------------------------------- ### Writing and Reading Objects with Chronicle Queue Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/How_it_works.adoc Demonstrates basic usage of Chronicle Queue for writing and reading custom objects. Ensure the MyObject class is defined and accessible. ```java public static void main(String[] args) throws IOException { // will write the .cq4 file to working directory try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.builder() .path(Files.createTempDirectory("queue").toFile()).build(); ExcerptAppender appender = queue.createAppender(); ExcerptTailer tailer = queue.createTailer()) { MyObject me = new MyObject(); me.name = "rob"; me.age = 40; // write 'MyObject' to the queue appender.writeDocument(me); // read 'MyObject' from the queue MyObject result = new MyObject(); tailer.readDocument(result); // System.out.println(result); } } } ``` -------------------------------- ### Get Current Chronicle Queue File Path Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/FAQ.adoc Retrieves and prints the absolute file path of the current Chronicle Queue store being written to for a given cycle. ```java WireStore wireStore = queue.storeForCycle(queue.cycle(), 0, false); System.out.println(wireStore.file().getAbsolutePath()); ``` -------------------------------- ### Package Chronicle Queue Tools Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/utilities.adoc Create a tar archive of the Chronicle Queue tools for deployment. This script is run from the project root. ```bash $ ./bin/package_scripts.sh Created /tmp/chronicle-queue-tools.tar ``` -------------------------------- ### Write Text and Get Index using DocumentContext Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/appending/pages/appending.adoc Shows how to write text data and retrieve the index where it was stored. This index can be used later to look up the excerpt. ```java try (final DocumentContext dc = appender.writingDocument()) { dc.wire().write().text("your text data“); System.out.println("your data was store to index="+ dc.index()); } ``` -------------------------------- ### Create Queue with WireType Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Use this to create a queue at a specified path with a given WireType. Note that not all wire types are supported. ```java // Creates a queue at "queuePath" and sets the WireType SingleChronicleQueueBuilder.builder(queuePath, wireType) ``` -------------------------------- ### Read Chronicle Queue from Specific Index Point Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/utilities.adoc Start reading messages from a Chronicle Queue at a given index point. Use the `-n` argument followed by the index. ```java $ mvn exec:java -Dexec.mainClass="net.openhft.chronicle.queue.ChronicleReaderMain" -Dexec.args="-d /data/queue -f -n 0x123ABE" ``` -------------------------------- ### Dump the data with Maven Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/demos/pages/message-history.adoc Use this command to read and display the data from the queue after publishing. ```sh mvn exec:java@DumpOutMain ``` -------------------------------- ### Get Last Appended Index Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/queue-operations/pages/indexing.adoc Retrieves the index of the last entry written by a specific thread-local appender. Note that in concurrent environments, this is not necessarily the absolute last entry in the queue. ```java long index = appender.lastIndexAppended(); ``` -------------------------------- ### Create Excerpt Appender and Tailer Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/FAQ.adoc Demonstrates how to create an ExcerptAppender for sequential writes and an ExcerptTailer for sequential reads from a Chronicle Queue. ```java ChronicleQueue queue = ChronicleQueue.singleBuilder(basePath).build(); // For sequential writes ExcerptAppender appender = queue.createAppender(); // sequential writes. // For sequential reads ideally, but random reads/write also possible ExcerptTailer tailer = queue.createTailer(); ``` -------------------------------- ### Move Tailer to Index Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/queue-operations/pages/indexing.adoc Repositions a tailer to a specific index in the queue. The next read operation will start from this index. Ensure the index is correctly formed using cycle and sequence number. ```java tailer.moveToIndex(long index); ``` -------------------------------- ### Run Chronicle History Reader Main with Maven Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/demos/pages/message-history.adoc Execute the Chronicle History Reader Main tool via Maven to inspect queue data. ```sh mvn exec:java@CHRM ``` -------------------------------- ### Using ValueOut Interface Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/MigratingToV4.adoc Illustrates writing primitive data types and text using the ValueOut interface within a DocumentContext. ```java try (DocumentContext dc = appender.writingDocument()) { ValueOut out = dc.wire().getValueOut(); out.int8(CODE); out.int64(timestamp); out.text(message); } ``` -------------------------------- ### Configure Pretoucher Properties Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Set system properties to configure Pretoucher behavior, such as enabling early cycle acquisition and setting the pretoucher preroll time. ```java System.setProperty("SingleChronicleQueueExcerpts.earlyAcquireNextCycle", "true"); System.setProperty("SingleChronicleQueueExcerpts.pretoucherPrerollTimeMs", "100"); ``` -------------------------------- ### Get Last Appended Index Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Demonstrates how to retrieve the last index appended by a specific ExcerptAppender. Note that this is thread-local and may not reflect the absolute last index in the queue if concurrent writes occur. ```java final ExcerptAppender appender = queue.createAppender(); long index = appender.lastIndexAppended(); ``` -------------------------------- ### Run ChronicleReaderMain with Classpath Source: https://github.com/openhft/chronicle-queue/blob/ea/README.adoc Execute ChronicleReaderMain by manually adding required JARs to the classpath. Replace the JAR name with the actual version. ```shell script $ java -cp chronicle-queue-5.20.108.jar net.openhft.chronicle.queue.ChronicleReaderMain -d ``` -------------------------------- ### ArchiveRollFiles Usage Help Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/command-line/pages/command_line_tools.adoc Displays the command-line interface usage for ArchiveRollFilesMain, outlining available parameters and their descriptions. ```shell script usage: ArchiveRollFilesMain -aa [-ad ] [-h] [-kc ] [-m ] [-qbme ] [-qbmn ] -qc -qn [-r ] [-vc ] -aa Archiving action to perform (ARCHIVE or DELETE) -ad Directory to move files to if archiving -dryrun Perform dry run of archiving actions that would occur without actual processing -h Print this help and exit -kc Name of key class (if queue being archived is backing a QBM) -m Archive files older than this age. Can be specified as milliseconds since epoch or local datetime. Either this or -r must be provided. -qbme Maximum number of entries in QBM (if queue being archived is backing a QBM) -qbmn QBM name (if queue is backing a QBM) -qc QueueReplicationConfig file containing queue configuration -qn Name of queue as used in queue-config-file -r Number of roll cycles to keep when archiving. Either this or -m must be provided. -vc Name of value class (if queue being archived is backing a QBM) ``` -------------------------------- ### Append to Raw Memory Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/queue-operations/pages/appending.adoc For low-level control, use `writeBytes` with a lambda to get a memory address and write data directly using `Unsafe` operations. Ensure to update the write position accordingly. ```java // Unsafe low level appender.writeBytes(b -> { long address = b.address(b.writePosition()); Unsafe unsafe = UnsafeMemory.UNSAFE; unsafe.putByte(address, (byte) 0x12); address += 1; unsafe.putInt(address, 0x345678); address += 4; unsafe.putLong(address, 0x999000999000L); address += 8; byte[] bytes = "Hello World".getBytes(StandardCharsets.ISO_8859_1); unsafe.copyMemory(bytes, Jvm.arrayByteBaseOffset(), null, address, bytes.length); b.writeSkip(1 + 4 + 8 + bytes.length); }); ``` -------------------------------- ### Create an ExcerptTailer Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/tailing/pages/tailing.adoc Initializes a Chronicle Queue and creates an ExcerptTailer to read messages. Ensure the queue path is correctly specified. ```java try (ChronicleQueue queue = ChronicleQueue.singleBuilder(path + "/trades").build()) { final ExcerptTailer tailer = queue.createTailer(); } ``` -------------------------------- ### Get Last Index in Queue Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/queue-operations/pages/indexing.adoc Retrieves the index of the very last data entry present in the queue. Returns -1 if the queue is empty. Be aware that this value might be an underestimate if the queue is being written to concurrently. ```java queue.lastIndex() ``` -------------------------------- ### Get removable roll file candidates from command line Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/managing_roll_files_directly.adoc Execute a Maven command to list removable roll file candidates for a specified directory. The output lists candidates per line. ```sh mvn exec:java -Dexec.mainClass="net.openhft.chronicle.queue.internal.main.InternalRemovableRollFileCandidatesMain" -Dexec.classScope=compile -Dexec.args="my_queue_dir" ``` -------------------------------- ### Write Document using Lambda Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/FAQ.adoc Demonstrates writing a document to a Chronicle Queue using a lambda expression, suitable for describing the message content. ```java appender.writeDocument(wire -> wire.write("FirstName").text("Steve") .write("Surname").text("Jobs")); ``` -------------------------------- ### Running ChronicleReaderMain with a JAR Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/queue-operations/pages/tailing.adoc Execute ChronicleReaderMain by specifying the JAR file and the directory containing the queue files. Ensure the JAR is on the classpath. ```shell $ java -cp chronicle-queue-5.20.108.jar net.openhft.chronicle.queue.ChronicleReaderMain -d ``` -------------------------------- ### Asynchronous Reads and Writes with Shared Memory Source: https://github.com/openhft/chronicle-queue/blob/ea/docs/antora/modules/async-mode/pages/async_mode.adoc Configures Chronicle Queue for asynchronous reads and writes using a shared memory-mapped file for inter-process communication. This example requires a compatible environment like /dev/shm. ```java // Common final File path = new File("."); final File ring = new File("/dev/shm/example.rb"); final int TAILERS = 5; // Appender process SingleChronicleQueueBuilder builder = ChronicleQueue.singleBuilder(path); try (@NotNull ChronicleQueue queue = builder.bufferCapacity(1 << 20) .maxTailers(TAILERS) .readBufferMode(BufferMode.Asynchronous) .writeBufferMode(BufferMode.Asynchronous) .asyncBufferCreator(AsyncBufferCreators.MappedFileDevShm) // share a memory-mapped ring in /dev/shm .build()) { ExcerptAppender appender = queue.createAppender(); ... } // Tailer processes - 1..TAILERS SingleChronicleQueueBuilder builder = ChronicleQueue.singleBuilder(path); // same path as process 1 try (@NotNull ChronicleQueue queue = builder.bufferCapacity(1 << 20) .maxTailers(TAILERS) .readBufferMode(BufferMode.Asynchronous) .writeBufferMode(BufferMode.Asynchronous) .asyncBufferCreator(AsyncBufferCreators.MappedFileDevShm) // share a memory-mapped ring in /dev/shm .build()) { ExcerptTailer tailer = queue.createTailer(); ... } ```