### Initialize Go Module and Get TigerBeetle Client Source: https://docs.tigerbeetle.com/coding/clients/go Installs the TigerBeetle client for Go. Ensure you are in your project directory. ```bash go mod init tbtest go get github.com/tigerbeetle/tigerbeetle-go ``` -------------------------------- ### Docker Compose Output Example Source: https://docs.tigerbeetle.com/operating/deploying/docker Example output when starting a multi-node TigerBeetle cluster using Docker Compose. ```text docker-compose up Starting tigerbeetle_0 ... done Starting tigerbeetle_2 ... done Recreating tigerbeetle_1 ... done Attaching to tigerbeetle_0, tigerbeetle_2, tigerbeetle_1 tigerbeetle_1 | info(io): opening "0_1.tigerbeetle"... tigerbeetle_2 | info(io): opening "0_2.tigerbeetle"... tigerbeetle_0 | info(io): opening "0_0.tigerbeetle"... tigerbeetle_0 | info(main): 0: cluster=0: listening on 0.0.0.0:3001 tigerbeetle_2 | info(main): 2: cluster=0: listening on 0.0.0.0:3003 tigerbeetle_1 | info(main): 1: cluster=0: listening on 0.0.0.0:3002 tigerbeetle_0 | info(message_bus): connected to replica 1 tigerbeetle_0 | info(message_bus): connected to replica 2 tigerbeetle_1 | info(message_bus): connected to replica 2 tigerbeetle_1 | info(message_bus): connection from replica 0 tigerbeetle_2 | info(message_bus): connection from replica 0 tigerbeetle_2 | info(message_bus): connection from replica 1 tigerbeetle_0 | info(clock): 0: system time is 83ns ahead tigerbeetle_2 | info(clock): 2: system time is 83ns ahead tigerbeetle_1 | info(clock): 1: system time is 78ns ahead ... and so on ... ``` -------------------------------- ### Verify TigerBeetle Client Setup Source: https://docs.tigerbeetle.com/coding/clients/dotnet A minimal C# program to verify that the TigerBeetle client library has been successfully installed and can be imported. ```csharp using System; using TigerBeetle; // Validate import works. Console.WriteLine("SUCCESS"); ``` -------------------------------- ### Basic Go Program Setup Source: https://docs.tigerbeetle.com/coding/clients/go A minimal Go program to verify the TigerBeetle client import. ```go package main import ( "fmt" "log" "os" . "github.com/tigerbeetle/tigerbeetle-go" ) func main() { fmt.Println("Import ok!") } ``` -------------------------------- ### Run Docker Compose Up Source: https://docs.tigerbeetle.com/operating/deploying/docker Command to start the services defined in the docker-compose.yml file. ```bash docker-compose up ``` -------------------------------- ### Install TigerBeetle .NET Client Source: https://docs.tigerbeetle.com/coding/clients/dotnet Installs the TigerBeetle client package for a new .NET console application. This command should be run after creating a new project directory. ```bash dotnet new console dotnet add package tigerbeetle ``` -------------------------------- ### Install TigerBeetle Python Client Source: https://docs.tigerbeetle.com/coding/clients/python Install the TigerBeetle client library using pip. Ensure you have Python 3.7 or higher. ```bash pip install tigerbeetle ``` -------------------------------- ### Quick Install TigerBeetle on Linux Source: https://docs.tigerbeetle.com/operating/installing Use this command to download and unzip the TigerBeetle binary for Linux. Verify the installation by checking the version. ```bash curl -Lo tigerbeetle.zip https://linux.tigerbeetle.com && unzip tigerbeetle.zip ./tigerbeetle version ``` -------------------------------- ### Start TigerBeetle Replicas Source: https://docs.tigerbeetle.com/operating/deploying Starts the TigerBeetle replicas for a three-replica cluster. The `--addresses` argument must be identical for all replicas and clients, with the order corresponding to the replica index. ```bash ./tigerbeetle start --addresses=127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002 ./0_0.tigerbeetle & ./tigerbeetle start --addresses=127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002 ./0_1.tigerbeetle & ./tigerbeetle start --addresses=127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002 ./0_2.tigerbeetle & ``` -------------------------------- ### Basic TigerBeetle Python Setup Source: https://docs.tigerbeetle.com/single-page Basic setup for the TigerBeetle Python client. This includes importing the library and printing a confirmation message. Debug logging can be enabled via Python's logging module or `tb.configure_logging`. ```python import os import tigerbeetle as tb print("Import OK!") # To enable debug logging, via Python's built in logging module: # logging.basicConfig(level=logging.DEBUG) # tb.configure_logging(debug=True) ``` -------------------------------- ### Start TigerBeetle Replica Source: https://docs.tigerbeetle.com/start Starts a single-replica TigerBeetle cluster listening on port 3000. The data is stored in the specified file. It's safe to interrupt with ^C. ```bash ./tigerbeetle start --addresses=3000 --development ./0_0.tigerbeetle ``` -------------------------------- ### Rust Project Setup with Cargo Source: https://docs.tigerbeetle.com/single-page Sets up a new Rust project using Cargo, including dependencies for TigerBeetle and futures. ```toml [package] name = "tigerbeetle-test" version = "0.1.0" edition = "2024" [dependencies] tigerbeetle.path = "../.." utures = "0.3" ``` -------------------------------- ### Create Multiple Transfers in Java Source: https://docs.tigerbeetle.com/coding/clients/java This example demonstrates creating multiple transfers in a single batch and handling the results. It iterates through the results to check the status of each transfer. ```java TransferBatch transfers = new TransferBatch(3); transfers.add(); transfers.setId(1); transfers.setDebitAccountId(102); transfers.setCreditAccountId(103); transfers.setAmount(10); transfers.setLedger(1); transfers.setCode(1); transfers.add(); transfers.setId(2); transfers.setDebitAccountId(102); transfers.setCreditAccountId(103); transfers.setAmount(10); transfers.setLedger(1); transfers.setCode(1); transfers.add(); transfers.setId(3); transfers.setDebitAccountId(102); transfers.setCreditAccountId(103); transfers.setAmount(10); transfers.setLedger(1); transfers.setCode(1); CreateTransferResultBatch transferResults = client.createTransfers(transfers); while (transferResults.next()) { switch (transferResults.getStatus()) { case Created: System.out.printf("Batch transfer at %d successfully created with timestamp %d.\n", transferResults.getPosition(), transferResults.getTimestamp()); break; case Exists: System.err.printf("Batch transfer at %d already exists with timestamp %d.\n", transferResults.getPosition(), transferResults.getTimestamp()); break; default: System.err.printf("Batch transfer at %d failed to create: %s\n", transferResults.getPosition(), transferResults.getStatus()); break; } } ``` -------------------------------- ### Initialize Go Project with TigerBeetle Client Source: https://docs.tigerbeetle.com/single-page Sets up a new Go project and installs the TigerBeetle client. Ensure you have Go >= 1.21 and a compatible Linux kernel (>= 5.6) for production. ```bash go mod init tbtest go get github.com/tigerbeetle/tigerbeetle-go ``` ```go package main import ( "fmt" "log" "os" . "github.com/tigerbeetle/tigerbeetle-go" ) func main() { fmt.Println("Import ok!") } ``` ```bash go run main.go ``` -------------------------------- ### Maven Project Setup (pom.xml) Source: https://docs.tigerbeetle.com/coding/clients/java Configure your Maven project to include the TigerBeetle Java client library. Ensure Java 11 and Maven 3.6+ are installed. ```xml 4.0.0 com.tigerbeetle samples 1.0-SNAPSHOT 11 11 org.apache.maven.plugins maven-compiler-plugin 3.8.1 -Xlint:all,-options,-path org.codehaus.mojo exec-maven-plugin 1.6.0 com.tigerbeetle.samples.Main com.tigerbeetle tigerbeetle-java 0.0.1-3431 ``` -------------------------------- ### Create and Lookup Accounts in TigerBeetle REPL Source: https://docs.tigerbeetle.com/start Demonstrates creating two accounts and then looking them up using the TigerBeetle REPL. Shows the initial state of the accounts. ```shell > create_accounts id=1 code=10 ledger=700, id=2 code=10 ledger=700; > lookup_accounts id=1, id=2; ``` -------------------------------- ### Rust Project Setup with TigerBeetle Source: https://docs.tigerbeetle.com/coding/clients/rust Configure your Rust project's Cargo.toml to include the TigerBeetle client and necessary dependencies. Ensure Rust 1.68+ is installed. ```toml [package] name = "tigerbeetle-test" version = "0.1.0" edition = "2024" [dependencies] tigerbeetle.path = "../.." utures = "0.3" ``` -------------------------------- ### Create Accounts in Go Source: https://docs.tigerbeetle.com/coding/clients/go Demonstrates creating multiple accounts in a single batch request. Handles success, existing accounts, and errors, logging the timestamp or status for each. ```go account0 := Account{ ID: ToUint128(102), Ledger: 1, Code: 718, Flags: 0, } account1 := Account{ ID: ToUint128(103), Ledger: 1, Code: 718, Flags: 0, } account2 := Account{ ID: ToUint128(104), Ledger: 1, Code: 718, Flags: 0, } accountResults, err := client.CreateAccounts([]Account{account0, account1, account2}) if err != nil { log.Printf("Error creating accounts: %s", err) return } for i, result := range accountResults { switch result.Status { case AccountCreated: log.Printf("Batch account at %d successfully created with timestamp %d.", i, result.Timestamp) case AccountExists: log.Printf("Batch account at %d already exists with timestamp %d.", i, result.Timestamp) default: log.Printf("Batch account at %d failed to create: %s", i, result.Status) } } ``` -------------------------------- ### Install Python Client Package Source: https://docs.tigerbeetle.com/operating/upgrading Command to install or update the TigerBeetle Python client package to a specific version. ```bash pip install tigerbeetle==0.15.4 ``` -------------------------------- ### Install Node.js Client Package Source: https://docs.tigerbeetle.com/operating/upgrading Command to install or update the TigerBeetle Node.js client package to a specific version. ```bash npm install --save-exact tigerbeetle-node@0.15.4 ``` -------------------------------- ### Create Accounts with TigerBeetle .NET Client Source: https://docs.tigerbeetle.com/coding/clients/dotnet Demonstrates creating multiple accounts in a batch and handling the results, including success, existing accounts, and failures. ```csharp var account0 = new Account { Id = 102, Ledger = 1, Code = 1, Flags = AccountFlags.None, }; var account1 = new Account { Id = 103, Ledger = 1, Code = 1, Flags = AccountFlags.None, }; var account2 = new Account { Id = 104, Ledger = 1, Code = 1, Flags = AccountFlags.None, }; var accountResults = client.CreateAccounts(new[] { account0, account1, account2 }); for (int i = 0; i < accountResults.Length; i++) { switch (accountResults[i].Status) { case CreateAccountStatus.Created: Console.WriteLine($"Batch account at {i} successfully created with timestamp {accountResults[i].Timestamp}."); break; case CreateAccountStatus.Exists: Console.WriteLine($"Batch account at {i} already exists with timestamp {accountResults[i].Timestamp}."); break; default: Console.WriteLine($"Batch account at {i} failed to create: {accountResults[i].Status}"); break; } } ``` -------------------------------- ### Quick Install TigerBeetle on macOS Source: https://docs.tigerbeetle.com/operating/installing Use this command to download and unzip the TigerBeetle binary for macOS. Verify the installation by checking the version. ```bash curl -Lo tigerbeetle.zip https://mac.tigerbeetle.com && unzip tigerbeetle.zip ./tigerbeetle version ``` -------------------------------- ### Create Multiple Accounts with Flags in Java Source: https://docs.tigerbeetle.com/coding/clients/java This example shows how to create multiple accounts in a single batch, applying different flags like LINKED and DEBITS_MUST_NOT_EXCEED_CREDITS. Combine enum values using bitwise-OR for flags. ```java AccountBatch accounts = new AccountBatch(2); accounts.add(); accounts.setId(100); accounts.setLedger(1); accounts.setCode(718); accounts.setFlags(AccountFlags.LINKED | AccountFlags.DEBITS_MUST_NOT_EXCEED_CREDITS); accounts.add(); accounts.setId(101); accounts.setLedger(1); accounts.setCode(718); accounts.setFlags(AccountFlags.HISTORY); CreateAccountResultBatch accountResults = client.createAccounts(accounts); // Results handling omitted. ``` -------------------------------- ### Create Accounts in Batches Source: https://docs.tigerbeetle.com/coding/clients/python Demonstrates creating multiple accounts in a single batch request and iterating through the results to check the status of each account creation. ```python account0 = tb.Account( id=102, debits_pending=0, debits_posted=0, credits_pending=0, credits_posted=0, user_data_128=0, user_data_64=0, user_data_32=0, ledger=1, code=1, timestamp=0, flags=0, ) account1 = tb.Account( id=103, debits_pending=0, debits_posted=0, credits_pending=0, credits_posted=0, user_data_128=0, user_data_64=0, user_data_32=0, ledger=1, code=1, timestamp=0, flags=0, ) account2 = tb.Account( id=104, debits_pending=0, debits_posted=0, credits_pending=0, credits_posted=0, user_data_128=0, user_data_64=0, user_data_32=0, ledger=1, code=1, timestamp=0, flags=0, ) account_results = client.create_accounts([account0, account1, account2]) for i, result in enumerate(account_results): if result.status == tb.CreateAccountStatus.CREATED: print(f"Batch account at {i} successfully created with timestamp {result.timestamp}.") elif result.status == tb.CreateAccountStatus.EXISTS: print(f"Batch account at {i} already exists with timestamp {result.timestamp}.") else: print(f"Batch account at {i} failed to create: {result.status}.") ``` -------------------------------- ### Install TigerBeetle Node.js Client Source: https://docs.tigerbeetle.com/coding/clients/node Install the TigerBeetle client for Node.js using npm. Ensure you are using Node.js version 18 or higher. ```bash npm install --save-exact tigerbeetle-node ``` -------------------------------- ### Basic Python Client Setup Source: https://docs.tigerbeetle.com/coding/clients/python Import the TigerBeetle library and print a confirmation message. Debug logging can be enabled using Python's logging module or `tb.configure_logging`. ```python import os import tigerbeetle as tb print("Import OK!") # To enable debug logging, via Python's built in logging module: # logging.basicConfig(level=logging.DEBUG) # tb.configure_logging(debug=True) ``` -------------------------------- ### Quick Install TigerBeetle on Windows Source: https://docs.tigerbeetle.com/operating/installing Use this PowerShell command to download and extract the TigerBeetle binary for Windows. Verify the installation by checking the version. ```powershell powershell -command "curl.exe -Lo tigerbeetle.zip https://windows.tigerbeetle.com; Expand-Archive tigerbeetle.zip ." .\tigerbeetle version ``` -------------------------------- ### Create Accounts with Flags Source: https://docs.tigerbeetle.com/coding/clients/dotnet Demonstrates creating accounts with specific flags enabled using bitwise OR operations. Flags like `Linked` and `DebitsMustNotExceedCredits` enforce specific account behaviors. ```csharp var account0 = new Account { Id = 100, Ledger = 1, Code = 1, Flags = AccountFlags.Linked | AccountFlags.DebitsMustNotExceedCredits, }; var account1 = new Account { Id = 101, Ledger = 1, Code = 1, Flags = AccountFlags.History, }; var accountResults = client.CreateAccounts(new[] { account0, account1 }); // Results handling omitted. ``` -------------------------------- ### Build and Run Rust Project Source: https://docs.tigerbeetle.com/coding/clients/rust Command to compile and execute your Rust project after setting up dependencies. ```bash cargo run ``` -------------------------------- ### Build and Run Go Program Source: https://docs.tigerbeetle.com/coding/clients/go Compiles and executes a Go program. ```bash go run main.go ``` -------------------------------- ### Batching Transfers from External Source in Java Source: https://docs.tigerbeetle.com/coding/clients/java This example shows how to efficiently batch transfers by reading data from an external source and sending them in batches up to the maximum size. It handles sending any remaining transfers after the loop. ```java ResultSet dataSource = null; /* Loaded from an external source. */; var BATCH_SIZE = 8189; TransferBatch batch = new TransferBatch(BATCH_SIZE); while(dataSource.next()) { batch.add(); batch.setId(dataSource.getBytes("id")); batch.setDebitAccountId(dataSource.getBytes("debit_account_id")); batch.setCreditAccountId(dataSource.getBytes("credit_account_id")); batch.setAmount(dataSource.getBigDecimal("amount").toBigInteger()); batch.setLedger(dataSource.getInt("ledger")); batch.setCode(dataSource.getInt("code")); if (batch.getLength() == BATCH_SIZE) { CreateTransferResultBatch transferResults = client.createTransfers(batch); // Results handling omitted. // Reset the batch for the next iteration. batch.beforeFirst(); } } if (batch.getLength() > 0) { // Send the remaining items. CreateTransferResultBatch transferResults = client.createTransfers(batch); // Results handling omitted. } ``` -------------------------------- ### Upgrade TigerBeetle Binary Installation Source: https://docs.tigerbeetle.com/operating/upgrading Steps to upgrade a binary-based TigerBeetle installation on each replica. This includes downloading the new binary, replacing the old one, and restarting the service if necessary. ```bash # SSH to each replica, in no particular order: cd /tmp wget https://github.com/tigerbeetle/tigerbeetle/releases/download/0.15.4/tigerbeetle-x86_64-linux.zip unzip tigerbeetle-x86_64-linux.zip # Put the binary on the same file system as the target, so mv is atomic. mv tigerbeetle /usr/bin/tigerbeetle-new mv /usr/bin/tigerbeetle /usr/bin/tigerbeetle-old mv /usr/bin/tigerbeetle-new /usr/bin/tigerbeetle # Restart TigerBeetle. Only required when upgrading from 0.15.3. # Otherwise, it will detect new versions are available and coordinate the upgrade itself. systemctl restart tigerbeetle # or, however you are managing TigerBeetle. ``` -------------------------------- ### Start TigerBeetle AMQP CDC Job Source: https://docs.tigerbeetle.com/operating/cdc Use this command to start the CDC job, streaming transfers and balance updates to an AMQP broker. Ensure the AMQP broker is accessible and configured with the specified exchange. ```bash ./tigerbeetle amqp --addresses=127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002 --cluster=0 \ --host=127.0.0.1 \ --vhost=/ \ --user=guest --password=guest \ --publish-exchange=tigerbeetle ``` -------------------------------- ### Create Accounts with Node.js Client Source: https://docs.tigerbeetle.com/coding/clients/node Demonstrates creating multiple accounts in a batch and handling the results, including success and error cases. Ensure CreateAccountStatus enum is imported. ```javascript const account0 = { id: 102n, debits_pending: 0n, debits_posted: 0n, credits_pending: 0n, credits_posted: 0n, user_data_128: 0n, user_data_64: 0n, user_data_32: 0, reserved: 0, ledger: 1, code: 1, timestamp: 0n, flags: 0, }; const account1 = { id: 103n, debits_pending: 0n, debits_posted: 0n, credits_pending: 0n, credits_posted: 0n, user_data_128: 0n, user_data_64: 0n, user_data_32: 0, reserved: 0, ledger: 1, code: 1, timestamp: 0n, flags: 0, }; const account2 = { id: 104n, debits_pending: 0n, debits_posted: 0n, credits_pending: 0n, credits_posted: 0n, user_data_128: 0n, user_data_64: 0n, user_data_32: 0, reserved: 0, ledger: 1, code: 1, timestamp: 0n, flags: 0, }; const account_results = await client.createAccounts([account0, account1, account2]); for (let i = 0; i < account_results.length; i++) { switch (account_results[i].status) { case CreateAccountStatus.created: console.error(`Batch account at ${i} successfully created with timestamp ${account_results[i].timestamp}.`); break; case CreateAccountStatus.exists: console.error(`Batch account at ${i} already exists with timestamp ${account_results[i].timestamp}.`); break; default: console.error(`Batch account at ${i} failed to create: ${account_results[i].status}`); break; } } ```