Services Info Register/KeepAlive/Publish/Subscribe. Based on etcd-rs, tokio

Overview

rs-service-util

How To Use: Test service register and watcher

() { println!("func_delete, need to delete k: {:?}", k); } #[tokio::main] async fn main() { // register service and keep alive tokio::spawn(async move { let mut regcli = RegSvcClient::new( vec![ "http://127.0.0.1:12379".to_owned(), "http://127.0.0.1:22379".to_owned(), "http://127.0.0.1:32379".to_owned() ], None, None, ).await.unwrap(); tokio::time::sleep(Duration::from_secs(10)).await; regcli.register_service(5, 30, "".to_owned(), "test".to_owned(), "key".to_owned(), "value".to_owned()).await.unwrap(); tokio::time::sleep(Duration::from_secs(30)).await; regcli.dispose_reg_svc_client().await.unwrap(); }); // watch service and call put/delete callback function tokio::spawn(async move { let mut moncli = MonSvcClient::new( vec![ "http://127.0.0.1:12379".to_owned(), "http://127.0.0.1:22379".to_owned(), "http://127.0.0.1:32379".to_owned() ], None, None, ).await.unwrap(); moncli.monitor_service("".to_owned(), &func_put, &func_delete).await.unwrap(); tokio::time::sleep(Duration::from_secs(100)).await; moncli.dispose_reg_svc_client().await.unwrap(); }); tokio::time::sleep(Duration::from_secs(120)).await; }">
use tokio;
use rs_service_util::svc::register::RegSvcClient;
use tokio::time::Duration;
use rs_service_util::svc::monitor::MonSvcClient;


fn func_put(k: String, v: String) -> () {
    println!("func_put, need to add kv: {:?}/{:?}", k, v);
}

fn func_delete(k: String) -> () {
    println!("func_delete, need to delete k: {:?}", k);
}

#[tokio::main]
async fn main() {
    // register service and keep alive
    tokio::spawn(async move {
        let mut regcli = RegSvcClient::new(
            vec![
                "http://127.0.0.1:12379".to_owned(),
                "http://127.0.0.1:22379".to_owned(),
                "http://127.0.0.1:32379".to_owned()
            ], None, None,
        ).await.unwrap();
        tokio::time::sleep(Duration::from_secs(10)).await;
        regcli.register_service(5, 30, "".to_owned(),
                                "test".to_owned(), "key".to_owned(),
                                "value".to_owned()).await.unwrap();
        tokio::time::sleep(Duration::from_secs(30)).await;
        regcli.dispose_reg_svc_client().await.unwrap();
    });

    // watch service and call put/delete callback function
    tokio::spawn(async move {
        let mut moncli = MonSvcClient::new(
            vec![
                "http://127.0.0.1:12379".to_owned(),
                "http://127.0.0.1:22379".to_owned(),
                "http://127.0.0.1:32379".to_owned()
            ], None, None,
        ).await.unwrap();
        moncli.monitor_service("".to_owned(), &func_put,
                               &func_delete).await.unwrap();
        tokio::time::sleep(Duration::from_secs(100)).await;
        moncli.dispose_reg_svc_client().await.unwrap();
    });

    tokio::time::sleep(Duration::from_secs(120)).await;
}

Dependencies

[dependencies]
tokio = { version = "1.2.0", features = ["full"] }
rs-service-util = { git = "https://github.com/mutalisk999/rs-service-util" }

Test log

func_put, need to add kv: "/etcd_services/test/key"/"value"
keep alive request at "2022-03-06 10:12:14.536026600 UTC"
service watcher put "/etcd_services/test/key" | "value" at "2022-03-06 10:12:14.535995300 UTC"
keep alive response: Ok(LeaseKeepAliveResponse { proto: LeaseKeepAliveResponse { header: Some(ResponseHeader { cluster_id: 17237436991929493444, member_id: 9372538179322589801, revision: 79, raft_term: 23 }), id: 3632574612849185088, ttl: 30 } }) at "2022-03-06 10:12:14.549221800 UTC"
keep alive request at "2022-03-06 10:12:19.538808600 UTC"
keep alive response: Ok(LeaseKeepAliveResponse { proto: LeaseKeepAliveResponse { header: Some(ResponseHeader { cluster_id: 17237436991929493444, member_id: 9372538179322589801, revision: 79, raft_term: 23 }), id: 3632574612849185088, ttl: 30 } }) at "2022-03-06 10:12:19.553139700 UTC"
keep alive request at "2022-03-06 10:12:24.544690600 UTC"
keep alive response: Ok(LeaseKeepAliveResponse { proto: LeaseKeepAliveResponse { header: Some(ResponseHeader { cluster_id: 17237436991929493444, member_id: 9372538179322589801, revision: 79, raft_term: 23 }), id: 3632574612849185088, ttl: 30 } }) at "2022-03-06 10:12:24.557441200 UTC"
keep alive request at "2022-03-06 10:12:29.556795600 UTC"
keep alive response: Ok(LeaseKeepAliveResponse { proto: LeaseKeepAliveResponse { header: Some(ResponseHeader { cluster_id: 17237436991929493444, member_id: 9372538179322589801, revision: 79, raft_term: 23 }), id: 3632574612849185088, ttl: 30 } }) at "2022-03-06 10:12:29.571412500 UTC"
keep alive request at "2022-03-06 10:12:34.564148600 UTC"
keep alive response: Ok(LeaseKeepAliveResponse { proto: LeaseKeepAliveResponse { header: Some(ResponseHeader { cluster_id: 17237436991929493444, member_id: 9372538179322589801, revision: 79, raft_term: 23 }), id: 3632574612849185088, ttl: 30 } }) at "2022-03-06 10:12:34.576709900 UTC"
keep alive request at "2022-03-06 10:12:39.570686500 UTC"
keep alive response: Ok(LeaseKeepAliveResponse { proto: LeaseKeepAliveResponse { header: Some(ResponseHeader { cluster_id: 17237436991929493444, member_id: 9372538179322589801, revision: 79, raft_term: 23 }), id: 3632574612849185088, ttl: 30 } }) at "2022-03-06 10:12:39.583784600 UTC"
[Cancel] keep alive response at "2022-03-06 10:12:44.546953300 UTC"
[Cancel] keep alive request at "2022-03-06 10:12:44.577212900 UTC"
func_delete, need to delete k: "/etcd_services/test/key"
service watcher delete "/etcd_services/test/key" at "2022-03-06 10:13:09.947781800 UTC"
[Cancel] service watcher at "2022-03-06 10:13:44.534192100 UTC"
You might also like...
OSINT from your favorite services in a friendly terminal user interface
OSINT from your favorite services in a friendly terminal user interface

osintui Open Source Intelligence Terminal User Interface Report Bug · Request Feature Installation First, install Rust (using the recommended rustup i

🦀Rust + Large Language Models - Make AI Services Freely and Easily. Inspired by LangChain

llmchain: Modern Data Transformations with LLM 🦀 + Large Language Models, inspired by LangChain. Features Models: LLMs & Chat Models & Embedding Mode

A fast, simple TUI for interacting with systemd services and their logs
A fast, simple TUI for interacting with systemd services and their logs

systemctl-tui A fast, simple TUI for interacting with systemd services and their logs. systemctl-tui can quickly browse service status and logs, and s

Cornucopia is a small CLI utility resting on tokio-postgres and designed to facilitate PostgreSQL workflows in Rust

Cornucopia Generate type checked Rust from your SQL Install | Example Cornucopia is a small CLI utility resting on tokio-postgres and designed to faci

Russh - Async (tokio) SSH2 client and server rimplementation

Russh Async (tokio) SSH2 client and server rimplementation. This is a fork of Thrussh by Pierre-Étienne Meunier which adds: More safety guarantees AES

Concurrent and multi-stage data ingestion and data processing with Rust+Tokio

TokioSky Build concurrent and multi-stage data ingestion and data processing pipelines with Rust+Tokio. TokioSky allows developers to consume data eff

Background task processing for Rust applications with Tokio, Diesel, and PostgreSQL.
Background task processing for Rust applications with Tokio, Diesel, and PostgreSQL.

Async persistent background task processing for Rust applications with Tokio. Queue asynchronous tasks to be processed by workers. It's designed to be

Fast Symbol Ranking based compressor. Based on the idea of Matt Mahoney's SR2

Fast Symbol Ranking based compressor. Based on the idea of Matt Mahoney's SR2

Terminal-based typing test.
Terminal-based typing test.

ttyper Ttyper is a terminal-based typing test built with Rust and tui-rs. installation With Cargo: cargo install ttyper usage For usage instructions,

Owner
Mutalisk
Mutalisk
Implemented reverse-engineered signature algorithm to successfully register with Apple's caching server.

View as English 项目描述 本项目通过逆向得到苹果缓存服务器的签名算法,并可以成功注册缓存服务。算法分为两种运行模式。 运行模式 直接运行(x64): 效率较高,但只支持64位CPU。已测试可运行在Windows/Linux/macOS上。 模拟器运行: 兼容性极高,支持所有CPU架构

null 6 Oct 27, 2023
`ls` alternative with useful info and a splash of color 🎨

?? Natls ?? Why Natls? Showing file permissions Showing file size Showing the date that the file was modified last Showing the user that the file belo

Will 1.2k Dec 19, 2022
`nm` and `addr2line` but for DI "debug-info" COFF files

Summary This is a very simple tool that prints out function, global, and source line information from a .dbg "DI" COFF debug file. This can handle bot

null 7 Dec 18, 2022
A super simple prompt for Fish shell, just shows git info and Vi mode.

vifi is a portmandeau of 'Vi' and 'Fish', because it's a prompt for Fish shell, primarily focused around showing proper indicators when using Vi key bindings.

Mat Jones 1 Sep 15, 2022
Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux.

Load Symbols Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux. Requirements Last tested wi

null 4 Jul 20, 2022
⚡🦀 Yet another rust system info fetcher.

Yarsi: Yet another rust sys info fetcher ✨ Showcase requirements ?? cargo ?? install with $ curl https://sh.rustup.rs -sSf | sh installation ❤️‍?? Ya

BinaryBrainiacs 8 Jan 26, 2023
FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.

Connect quickly to your services ?? FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config. Instal

Julien 85 Dec 14, 2022
a Rust library implementing safe, lightweight context switches, without relying on kernel services

libfringe libfringe is a library implementing safe, lightweight context switches, without relying on kernel services. It can be used in hosted environ

edef 473 Dec 28, 2022
This repo contains crates that are used to create the micro services and keep shared code in a common place.

MyEmma Helper Crates This repo contains crates that can are reused over different services. These crate are used in projects at MyEmma. But these crat

MyEmma 1 Jan 14, 2022
A small CLI tool to query ArcGIS REST API services, implemented in Rust. The server response is returned as pretty JSON.

A small CLI tool to query ArcGIS REST API services, implemented in Rust. The server response is returned as pretty JSON.

Andrew Vitale 2 Apr 25, 2022