Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Embedded tsoracle server

The minimum library-use case for tsoracle: opens a FileDriver, builds a Server with sensible defaults, and serves gRPC. This is the example to start from when you want tsoracle running inside your own binary rather than as a separate tsoracle serve process.

The full walkthrough lives in Embedding the server; this README is the run-it-now quickstart.

Run

cargo run -p example-embedded-server

The server binds 127.0.0.1:50551 and persists state under ./tsoracle-embedded-data/. Ctrl-C drains in-flight RPCs and exits cleanly; any committed high-water extension was fsynced before the server handed out timestamps from that window.

Talk to it from another terminal with grpcurl:

grpcurl -plaintext -d '{"count":1}' 127.0.0.1:50551 tsoracle.v1.TsoService/GetTs

Or from Rust using the tsoracle-client crate — see Calling tsoracle from Rust.

What to look at in src/main.rs

  • FileDriver::open_or_init(dir) is idempotent: the first run creates the state file, subsequent runs rehydrate from it.
  • Server::builder().consensus_driver(driver).build() is the minimum required configuration. clock, window_ahead, and failover_advance get their defaults (3 s / 1 s).
  • serve_with_shutdown(addr, future) drains in-flight RPCs when the shutdown future completes, then exits.

When this example is not the right shape

  • You want HA. This example uses FileDriver, which is single-node by design. Swap it for a ConsensusDriver over your replicated log — see examples/openraft-standalone (own raft) or examples/openraft-piggyback (shared raft) for worked versions.
  • You want to share a tonic listener with other services. Use Server::into_router instead of serve_with_shutdown; it returns a Result wrapping a tonic Routes value plus a WatchGuard owning the leader-watch task (the outer Result surfaces a ServerError::ReflectionInit if the embedded descriptor set fails to decode under the reflection feature). Keep the guard alive for as long as the routes should serve, and drop it (or call shutdown().await) at your own shutdown to cooperatively stop the watch task; shutdown().await surfaces any watch failure to your embedding process.