{"id":20834949,"url":"https://github.com/hstreamdb/hstreamdb-rust","last_synced_at":"2025-05-08T02:23:48.684Z","repository":{"id":58819610,"uuid":"529571900","full_name":"hstreamdb/hstreamdb-rust","owner":"hstreamdb","description":"Rust client library for HStreamDB","archived":false,"fork":false,"pushed_at":"2023-05-05T08:54:22.000Z","size":158,"stargazers_count":5,"open_issues_count":14,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T07:42:11.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hstreamdb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-27T11:56:53.000Z","updated_at":"2023-05-18T16:09:01.000Z","dependencies_parsed_at":"2023-02-10T09:01:28.032Z","dependency_job_id":null,"html_url":"https://github.com/hstreamdb/hstreamdb-rust","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hstreamdb%2Fhstreamdb-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hstreamdb%2Fhstreamdb-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hstreamdb%2Fhstreamdb-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hstreamdb%2Fhstreamdb-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hstreamdb","download_url":"https://codeload.github.com/hstreamdb/hstreamdb-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252985100,"owners_count":21835921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T00:22:00.741Z","updated_at":"2025-05-08T02:23:48.658Z","avatar_url":"https://github.com/hstreamdb.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hstreamdb-rust\n\n[\u003cimg alt=\"github\"       src=\"https://img.shields.io/badge/github-hstreamdb/hstreamdb_rust-8da0cb?style=for-the-badge\u0026logo=github\"                   height=\"24\"\u003e](https://github.com/hstreamdb/hstreamdb-rust)\n[\u003cimg alt=\"crates.io\"    src=\"https://img.shields.io/crates/v/hstreamdb.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\"                              height=\"24\"\u003e](https://crates.io/crates/hstreamdb)\n[\u003cimg alt=\"docs.rs\"      src=\"https://img.shields.io/badge/docs.rs-hstreamdb-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logo=docs.rs\"              height=\"24\"\u003e](https://docs.rs/hstreamdb)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/hstreamdb/hstreamdb-rust/ci.yml?branch=main\u0026style=for-the-badge\" height=\"24\"\u003e](https://github.com/hstreamdb/hstreamdb-rust/actions/workflows/ci.yml)\n\nRust client library for HStreamDB.\n\n### compatibility\n\nThis library is experimental and work in progress, please use the latest released version on [crates.io](https://crates.io/crates/hstreamdb).\n\n| client library version | HStream server version      |\n| ---------------------- | --------------------------- |\n| `v0.1.*`               | \u003e= `v0.9.4` \u0026\u0026 \u003c= `v0.9.7`  |\n| `v0.2.*`               | \u003e= `v0.9.4` \u0026\u0026 \u003c= `v0.12.0` |\n\n\n## Example Usage\n\n### Write Data to Streams\n\n```rust\nuse std::env;\n\nuse hstreamdb::client::Client;\nuse hstreamdb::producer::FlushSettings;\nuse hstreamdb::{CompressionType, Payload, Record, Stream};\nuse rand::distributions::Alphanumeric;\nuse rand::{thread_rng, Rng};\n\nasync fn produce_example() -\u003e anyhow::Result\u003c()\u003e {\n    let mut client = Client::new(env::var(\"TEST_SERVER_ADDR\")?).await?;\n\n    let stream_name = \"test_stream\";\n\n    client\n        .create_stream(Stream {\n            stream_name: \"test_stream\".to_string(),\n            replication_factor: 3,\n            backlog_duration: 7 * 24 * 3600,\n            shard_count: 12,\n        })\n        .await?;\n    println!(\"{:?}\", client.list_streams().await?);\n\n    // `Appender` is cheap to clone\n    let (appender, mut producer) = client\n        .new_producer(\n            stream_name.to_string(),\n            hstreamdb_pb::CompressionType::Zstd,\n            FlushSettings {\n                len: 10,\n                size: 4000 * 20,\n            },\n        )\n        .await?;\n\n    _ = tokio::spawn(async move {\n        let mut appender = appender;\n\n        for _ in 0..10 {\n            for _ in 0..100 {\n                let i: u32 = rand::random();\n                let payload: Vec\u003cu8\u003e = thread_rng()\n                    .sample_iter(\u0026Alphanumeric)\n                    .take(20)\n                    .map(char::from)\n                    .collect::\u003cString\u003e()\n                    .into_bytes();\n                appender\n                    .append(Record {\n                        partition_key: format!(\"test_partition_key_{i}\"),\n                        payload: Payload::RawRecord(payload),\n                    })\n                    .unwrap();\n            }\n        }\n        drop(appender)\n    });\n\n    // when all `Appender`s for the corresponding `Producer` have been dropped,\n    // the `Producer` will wait for all requests to be done and then stop\n    producer.start().await;\n\n    Ok(())\n}\n```\n\n### Read Data from Subscriptions\n\n``` rust\nuse std::env;\n\nuse hstreamdb::client::Client;\nuse hstreamdb::{SpecialOffset, Subscription};\nuse tokio_stream::StreamExt;\n\nasync fn consume_example() -\u003e anyhow::Result\u003c()\u003e {\n    let addr = env::var(\"TEST_SERVER_ADDR\").unwrap();\n    let mut client = Client::new(addr).await.unwrap();\n\n    let stream_name = \"test_stream\";\n    let subscription_id = \"test_subscription\";\n\n    client\n        .create_subscription(Subscription {\n            subscription_id: subscription_id.to_string(),\n            stream_name: stream_name.to_string(),\n            ack_timeout_seconds: 60 * 60,\n            max_unacked_records: 1000,\n            offset: SpecialOffset::Earliest,\n        })\n        .await?;\n    println!(\"{:?}\", client.list_subscriptions().await?);\n\n    let mut stream = client\n        .streaming_fetch(\"test_consumer\".to_string(), subscription_id.to_string())\n        .await\n        .unwrap();\n    let mut records = Vec::new();\n    while let Some((record, ack)) = stream.next().await {\n        println!(\"{record:?}\");\n        records.push(record);\n        ack().unwrap();\n        if records.len() == 10 * 100 {\n            println!(\"done\");\n            break;\n        }\n    }\n\n    client\n        .delete_subscription(subscription_id.to_string(), true)\n        .await?;\n\n    Ok(())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhstreamdb%2Fhstreamdb-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhstreamdb%2Fhstreamdb-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhstreamdb%2Fhstreamdb-rust/lists"}