8 个版本 (3 个稳定版)
2.0.1 | 2023 年 8 月 12 日 |
---|---|
2.0.0 | 2023 年 5 月 1 日 |
1.0.0 | 2023 年 4 月 23 日 |
0.1.4 | 2023 年 4 月 16 日 |
#5 in #subject
被 2 个 crate 使用
44KB
854 代码行
Schema registry API
提供与 schema registry 进行交互的 REST API。
示例
列出主题
use reqwest::Url;
use schema_registry_api::SchemaRegistry;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a `SchemaRegistry`
let base_url = Url::parse("https://127.0.0.1:8081")?;
let sr = SchemaRegistry::build_default(base_url)?;
// List subjects
let subjects = sr.subject().list(None, None).await?;
if subjects.is_empty() {
println!("No subject found");
}
for subject in &subjects {
println!("Found subject '{subject}'");
}
Ok(())
}
注册一个 schema
use reqwest::Url;
use schema_registry_api::{RegisterSchema, SchemaRegistry};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a `SchemaRegistry`
let base_url = Url::parse("https://127.0.0.1:8081")?;
let sr = SchemaRegistry::build_default(base_url)?;
// Create a subject
let subject = "a-topic-value".parse()?;
// Create the `RegisterSchema`
let schema = RegisterSchema {
schema: include_str!("../tests/assets/a_record.avsc").to_string(),
..Default::default()
};
// Register the schema for the subject
let registered_schema = sr.subject().new_version(&subject, &schema, None).await?;
// Get the schema id
let schema_id = registered_schema.id;
println!("The schema #{schema_id} is registered for subject '{subject}'");
Ok(())
}
许可证
许可方式为以下之一
- Apache 许可证 2.0 版 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确声明,否则您提交的任何贡献,根据 Apache-2.0 许可证的定义,应以上述方式双许可,不附加任何额外条款或条件。
依赖
~4–19MB
~299K SLoC