5 个版本

新版本 0.1.5 2024 年 8 月 24 日
0.1.4 2024 年 8 月 15 日
0.1.2 2024 年 8 月 8 日
0.1.1 2024 年 7 月 6 日
0.1.0 2024 年 6 月 29 日

#485 in 异步

Download history 120/week @ 2024-06-24 113/week @ 2024-07-01 26/week @ 2024-07-08 91/week @ 2024-08-05 121/week @ 2024-08-12

212 每月下载量

Apache-2.0

160KB
3K SLoC

Danube-client

与多瑙河 Pub/Sub 消息平台交互的异步 Rust 客户端库。

Danube 是一个用 Rust 编写的开源 分布式 Pub/Sub 消息平台。请参阅 文档 了解支持的概念和平台架构。

我正在努力改进它并添加新功能。请随时贡献或报告您遇到的问题。

示例用法

查看 示例文件

生产者

let client = DanubeClient::builder()
    .service_url("http://127.0.0.1:6650")
    .build()
    .unwrap();

let topic_name = "/default/test_topic";
let producer_name = "test_prod";

let mut producer = client
    .new_producer()
    .with_topic(topic_name)
    .with_name(producer_name)
    .build();

producer.create().await?;
println!("The Producer {} was created", producer_name);

let encoded_data = "Hello Danube".as_bytes().to_vec();

let message_id = producer.send(encoded_data, None).await?;
println!("The Message with id {} was sent", message_id);

消费者

let client = DanubeClient::builder()
        .service_url("http://127.0.0.1:6650")
        .build()
        .unwrap();

    let topic = "/default/test_topic";
    let consumer_name = "test_cons";
    let subscription_name = "test_subs";

    let mut consumer = client
        .new_consumer()
        .with_topic(topic)
        .with_consumer_name(consumer_name)
        .with_subscription(subscription_name)
        .with_subscription_type(SubType::Exclusive)
        .build();

    // Subscribe to the topic
    consumer.subscribe().await?;
    println!("The Consumer {} was created", consumer_name);

    // Start receiving messages
    let mut message_stream = consumer.receive().await?;

    while let Some(message) = message_stream.recv().await {
        let payload = message.payload;

        let result = String::from_utf8(payload);

        match result {
            Ok(message) => println!("Received message: {:?}", message),
            Err(e) => println!("Failed to convert Payload to String: {}", e),
        }
    }

贡献

查看 文档 了解如何设置多瑙河代理。

依赖

~6–13MB
~145K SLoC