Coder Social home page Coder Social logo

second-state / wasmedge-anna-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wasmedge/wasmedge-anna-client

0.0 2.0 0.0 120 KB

Rust client for the anna-rs KVS that can run in the WasmEdge Runtime

License: Apache License 2.0

Rust 100.00%

wasmedge-anna-client's Introduction

anna-rs client for WebAssembly

wasmedge-anna-client is a Rust client for anna-rs based on Tokio for WasmEdge. It communicates with anna-rs routing nodes and KVS nodes via vanilla TCP connections instead of Zenoh.

The wasmedge-anna-client can be compiled into WebAssembly. The WebAssembly app can run inside the WasmEdge Runtime as a lightweight and secure alternative to natively compiled apps in Linux container.

Usage

use std::time::Duration;
use wasmedge_anna_client::{Client, ClientConfig};

let mut client = Client::new(ClientConfig {
    routing_ip: "127.0.0.1".parse().unwrap(),
    routing_port_base: 12340,
    routing_threads: 1,
    timeout: Duration::from_secs(10),
})?;

// put the value
client.put_lww("foo".into(), "bar".into()).await?;

// sleep 1 second
tokio::time::sleep(Duration::from_secs(1)).await;

// get the value
let bytes = client.get_lww("foo".into()).await?;
let value = String::from_utf8(bytes)?;
println!("Successfully GET value of `foo`: {}", value);

Run the example

First, run routing node and KVS node of anna-rs:

$ cd anna-rs
$ cp example-config.yml config.yml
$ ANNA_PUBLIC_IP=127.0.0.1 ANNA_TCP_PORT_BASE=12340 cargo run --bin routing -- config.yml
$ # in another shell
$ ANNA_PUBLIC_IP=127.0.0.1 cargo run --bin kvs -- config.yml

Then, build and run the example app of wasmedge-anna-client:

$ cd example
$ cargo build --target wasm32-wasi
$ /path/to/wasmedge --dir .:. target/wasm32-wasi/debug/example.wasm

You can find more examples in wasmedge-db-examples.

Attribution

Many code of this driver is derived from anna-rs.

wasmedge-anna-client's People

Contributors

stdrc avatar juntao avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.