Zeebe Rust Client
A rust client for defining, orchestrating, and monitoring business processes
across microservices using Zeebe.
What is Zeebe?
Zeebe is a workflow engine for microservices orchestration. Zeebe ensures
that, once started, flows are always carried out fully, retrying steps in case
of failures. Along the way, Zeebe maintains a complete audit log so that the
progress of flows can be monitored. Zeebe is fault tolerant and scales
seamlessly to handle growing transaction volumes.
Example
use serde_json::json;
use zeebe::{Client, Job};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::default();
client
.deploy_workflow()
.with_resource_file("examples/workflows/order-process.bpmn")
.send()
.await?;
client
.create_workflow_instance()
.with_bpmn_process_id("order-process")
.with_latest_version()
.with_variables(json!({"orderId": 1234}))
.send()
.await?;
client
.job_worker()
.with_job_type("payment-service")
.with_handler(handle_job)
.run()
.await?;
Ok(())
}
async fn handle_job(client: Client, job: Job) {
let _ = client.complete_job().with_job_key(job.key()).send().await;
}
Or with job success and failure reported for you automatically from your
function result:
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::new();
#[derive(Error, Debug)]
enum MyError {
#[error("unknown error occurred")]
Unknown,
}
#[derive(Deserialize)]
struct MyJobData {
my_property: String,
my_other_property: String,
}
#[derive(Serialize)]
struct MyJobResult {
result: u32,
}
async fn handle_job(data: Data<MyJobData>) -> Result<MyJobResult, MyError> {
Ok(MyJobResult { result: 42 })
}
let job = client
.job_worker()
.with_job_type("my-job-type")
.with_auto_handler(handle_job)
.run()
.await?;
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(())
}