#微服务 #作业 #作业队列 #队列 #异步 #API绑定 #作业

zeebe

使用Zeebe定义、编排和监控跨微服务的业务流程的Rust客户端

10个版本

0.4.2 2022年8月3日
0.4.1 2021年12月14日
0.3.1 2021年3月5日
0.3.0 2021年2月1日
0.1.0 2020年7月30日

#1100异步

Download history 113/week @ 2024-04-02 4/week @ 2024-04-09 13/week @ 2024-04-16 1/week @ 2024-04-23 19/week @ 2024-04-30

141 每月下载量

MIT 许可证

110KB
2K SLoC

Zeebe Rust客户端

Build Status Crates.io: zeebe Documentation License: MIT

使用Zeebe定义、编排和监控跨微服务的业务流程的Rust客户端。

什么是Zeebe?

Zeebe是一个用于微服务编排的工作流引擎。Zeebe确保一旦启动,流程总是完全执行,在失败时重试步骤。在这个过程中,Zeebe维护一个完整的审计日志,以便可以监控流程的进度。Zeebe具有容错能力,并且可以无缝扩展以处理不断增长的交易量。

示例

use serde_json::json;
use zeebe::{Client, Job};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a zeebe client
    let client = Client::from_env()?;

    // Deploy a process
    client
        .deploy_process()
        .with_resource_file("examples/workflows/order-process.bpmn")
        .send()
        .await?;

    // Create a new process instance
    client
        .create_process_instance()
        .with_bpmn_process_id("order-process")
        .with_latest_version()
        .with_variables(json!({"orderId": 1234}))
        .send()
        .await?;

    // Process the instance with a worker
    client
        .job_worker()
        .with_job_type("payment-service")
        .with_handler(handle_job)
        .run()
        .await?;

    Ok(())
}

async fn handle_job(client: Client, job: Job) {
    /// your job processing logic...

    let _ = client.complete_job().with_job_key(job.key()).send().await;
}

或者,从您函数的结果自动报告作业成功和失败

use futures::future;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use zeebe::{Client, Data};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::from_env()?;

    // Given an app-specific error
    #[derive(Error, Debug)]
    enum MyError {
        #[error("unknown error occurred")]
        Unknown,
    }

    // And app-specific job data
    #[derive(Deserialize)]
    struct MyJobData {
        my_property: String,
        my_other_property: String,
    }

    // And app-specific job result
    #[derive(Serialize)]
    struct MyJobResult {
        result: u32,
    }

    // Async job handler function
    async fn handle_job(data: Data<MyJobData>) -> Result<MyJobResult, MyError> {
       Ok(MyJobResult { result: 42 })
    }

    // You can run a worker from your function with results auto reported
    let job = client
        .job_worker()
        .with_job_type("my-job-type")
        .with_auto_handler(handle_job)
        .run()
        .await?;

    // OR you can run a closure and have the results auto reported
    let job = client
        .job_worker()
        .with_job_type("my-job-type")
        .with_auto_handler(|my_job_data: Data<MyJobData>| {
            future::ok::<_, MyError>(MyJobResult { result: 42 })
        })
        .run()
        .await?;

    Ok(())
}

依赖项

~17–30MB
~574K SLoC