#schema #registry #subject #url #id #schema-registry

schema-registry-api

schema-registry 的 REST API

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 使用

MIT/Apache 许可证

44KB
854 代码行

Schema registry API

Crates.io Documentation Codecov Dependency status

提供与 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 许可证的定义,应以上述方式双许可,不附加任何额外条款或条件。

依赖

~4–19MB
~299K SLoC