Skip to content

Instantly share code, notes, and snippets.

@ChillFish8
Created January 6, 2023 14:43
Show Gist options
  • Save ChillFish8/fb71b715d69d47b89c91dc9f5910d451 to your computer and use it in GitHub Desktop.
Save ChillFish8/fb71b715d69d47b89c91dc9f5910d451 to your computer and use it in GitHub Desktop.
use std::net::SocketAddr;
use datacake_node::{ConnectionConfig, DCAwareSelector, DatacakeNodeBuilder};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let bind_addr = "127.0.0.1:8000".parse::<SocketAddr>().unwrap();
// We setup our connection config for the node passing in the bind address, public address and seed nodes.
// Here we're just using the bind address as our public address with no seed, but in the real world
// this will be a different value when deployed across several servers with seeds to contact.
let connection_cfg = ConnectionConfig::new(bind_addr, bind_addr, Vec::<String>::new());
// Our builder lets us configure the node.
//
// We can configure the node selector, data center of the node, cluster ID, etc...
let my_node = DatacakeNodeBuilder::<DCAwareSelector>::new(1, connection_cfg).connect().await?;
// Now we're connected we can add any extensions at runtime, our RPC server will already be
// running and setup.
//
// Check out the `datacake-eventual-consistency` implementation for a demo.
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment