#消息传递 #实时 #API 绑定 #生产者 #memphis

memphis-rust-community

Memphis 消息协议的 Rust 实现

9 个不稳定版本 (3 个破坏性版本)

0.4.0 2023 年 10 月 12 日
0.3.2 2023 年 8 月 16 日
0.2.1 2023 年 7 月 21 日
0.1.3 2023 年 7 月 12 日
0.1.2 2023 年 6 月 27 日

#1230网络编程

Download history 18/week @ 2024-03-10 24/week @ 2024-03-31 15/week @ 2024-04-07

每月 132 次下载

GPL-3.0 许可证

80KB
2K SLoC

Build Status docs.rs Crates.io Crates.io Crates.io

Memphis Rust 客户端

这是一个用 Rust 编写的 Memphis 非官方客户端。

安装

将以下内容添加到您的 Cargo.toml 文件中

[dependencies]
memphis-rust-community = "0.4.0"

用法

消费者

use memphis_rust_community::memphis_client::MemphisClient;
use memphis_rust_community::consumer::MemphisConsumerOptions;
use memphis_rust_community::station::MemphisStationsOptions;

#[tokio::main]
async fn main() {
    let client = MemphisClient::new("localhost:6666", "root", "memphis", None).await.unwrap();

    let station_options = MemphisStationsOptions::new("my-station");
    let station = client.create_station(station_options).await.unwrap();

    let consumer_options = MemphisConsumerOptions::new("my-consumer")
        .with_generate_unique_suffix(true);
    let consumer = station.create_consumer(consumer_options).await.unwrap();

    let mut message_receiver = consumer.consume().await.unwrap();
    tokio::spawn(async move {
        loop {
            let msg = message_receiver.recv().await;
            // Do something with the message
            break;
        }
    });
}

生产者

use memphis_rust_community::memphis_client::MemphisClient;
use memphis_rust_community::producer::MemphisProducerOptions;
use memphis_rust_community::station::MemphisStationsOptions;

#[tokio::main]
async fn main() {
    let client = MemphisClient::new("localhost:6666", "root", "memphis", None).await.unwrap();

    let station_options = MemphisStationsOptions::new("my-station");
    let station = client.create_station(station_options).await.unwrap();

    let producer_options = MemphisProducerOptions::new("my-producer")
        .with_generate_unique_suffix(true);

    let mut producer = station.create_producer(producer_options).await.unwrap();

    let msg = ComposableMessage::new()
        .with_payload("Hello World!")
        .with_header("TestHeader", "TestValue");

    producer.produce(msg).await.unwrap();
}

支持的功能

  • ✅ 连接
  • ✅ 断开连接
  • ✅ 创建站点
  • ✅ 销毁站点
  • ✅ 保留
  • ✅ 保留值
  • ✅ 存储类型

  • ⚠️ Schemaverse(WIP。默认情况下通过功能标志禁用)
  • ❌ 创建新模式
  • ❌ 强制 Protobuf 模式
  • ✅ 强制 Json 模式
  • ❌ 强制 GraphQL 模式
  • ❌ 分离模式

  • ✅ 生产
  • ✅ 添加头信息
  • ✅ 异步生产
  • ✅ 消息 ID
  • ✅ 销毁生产者
  • ✅ 消费
  • ✅ 确认消息
  • ❌ 获取
  • ✅ 消息延迟
  • ✅ 获取头信息
  • ✅ 获取消息序列号
  • ✅ 销毁消费者
  • ✅ 检查代理是否连接
  • ✅ 消费者预取

依赖项

~20–36MB
~661K SLoC