deploy_resource/
deploy_resource.rs

1use serde::{Deserialize, Serialize};
2use std::{path::PathBuf, time::Duration};
3use tokio::time::sleep;
4
5#[derive(Debug, Serialize, Deserialize)]
6struct HelloWorld {
7    hello: String,
8}
9
10//ZEEBE_AUTHENTICATION_MODE=identity docker compose up -d
11//URL: http://localhost:26500
12//Client ID: zeebe
13//Client secret: zecret
14//OAuth URL: http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token
15//Audience: zeebe-api
16#[tokio::main]
17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18    unsafe { std::env::set_var("RUST_BACKTRACE", "1") };
19
20    let client = zeebe_rs::Client::builder()
21        .with_address("http://localhost", 26500)
22        .with_oauth(
23            String::from("zeebe"),
24            String::from("zecret"),
25            String::from(
26                "http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token",
27            ),
28            String::from("zeebe-api"),
29            Duration::from_secs(30),
30            None,
31        )
32        .build()
33        .await?;
34
35    let _ = client.auth_initialized().await;
36    let result = client
37        .deploy_resource()
38        .with_resource_file(PathBuf::from("./examples/resources/hello_world.bpmn"))
39        .read_resource_files()?
40        .send()
41        .await?;
42
43    println!("{:?}", result);
44
45    let result = client
46        .publish_message()
47        .with_name(String::from("hello_world"))
48        .without_correlation_key()
49        .with_variables(HelloWorld {
50            hello: String::from("foo"),
51        })?
52        .send()
53        .await?;
54
55    println!("{:?}", result);
56
57    sleep(Duration::from_secs(1)).await;
58
59    let result = client
60        .publish_message()
61        .with_name(String::from("hello_message"))
62        .with_correlation_key(String::from("foo"))
63        .send()
64        .await?;
65
66    println!("{:?}", result);
67
68    Ok(())
69}