Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

Client used to communicate with Zeebe.

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Create a new client with default config.

Source

pub fn from_env() -> Result<Self>

Create a new client from environment variables

Source

pub fn from_config(config: ClientConfig) -> Result<Self>

Build a new Zeebe client from a given configuration.

§Examples
use zeebe::{Client, ClientConfig};
let endpoints = vec!["http://0.0.0.0:26500".to_string()];

let client = Client::from_config(ClientConfig::with_endpoints(endpoints));

with TLS (see the ClientTlsConfig docs for configuration):

use zeebe::{Client, ClientConfig};
use tonic::transport::ClientTlsConfig;

let endpoints = vec!["http://0.0.0.0:26500".to_string()];
let tls = ClientTlsConfig::new();

let client = Client::from_config(ClientConfig {
    endpoints,
    tls: Some(tls),
    auth: None,
})?;
Source

pub async fn auth_initialized(&self) -> Result<()>

Future that resolves when the auth interceptor is initialized.

Source

pub fn topology(&self) -> TopologyBuilder

Obtains the current topology of the cluster the gateway is part of.

§Examples
let client = zeebe::Client::new();

let topology = client.topology().send().await?;
Source

pub fn deploy_process(&self) -> DeployProcessBuilder

Deploys one or more processes to Zeebe. Note that this is an atomic call, i.e. either all processes are deployed, or none of them are.

§Examples
let client = zeebe::Client::new();

let process = client
    .deploy_process()
    .with_resource_file("path/to/process.bpmn")
    .send()
    .await?;
Source

pub fn create_process_instance(&self) -> CreateProcessInstanceBuilder

Creates and starts an instance of the specified process.

The process definition to use to create the instance can be specified either using its unique key (as returned by deploy_process), or using the BPMN process ID and a version. Pass -1 as the version to use the latest deployed version.

Note that only processes with none start events can be started through this command.

§Examples
use serde_json::json;

let client = zeebe::Client::new();

let process_instance = client
    .create_process_instance()
    .with_bpmn_process_id("example-process")
    .with_latest_version()
    .with_variables(json!({"myData": 31243}))
    .send()
    .await?;
Source

pub fn create_process_instance_with_result( &self, ) -> CreateProcessInstanceWithResultBuilder

Similar to create_process_instance, creates and starts an instance of the specified process_

Unlike create_process_instance, the response is returned when the process_is completed.

Note that only processes with none start events can be started through this command.

§Examples
use serde_json::json;

let client = zeebe::Client::new();

let process_instance_with_result = client
    .create_process_instance_with_result()
    .with_bpmn_process_id("example-process")
    .with_latest_version()
    .with_variables(json!({"myData": 31243}))
    .send()
    .await?;
Source

pub fn cancel_process_instance(&self) -> CancelProcessInstanceBuilder

Cancels a running process instance.

§Examples
let client = zeebe::Client::new();

// process instance key, e.g. from a `CreateProcessInstanceResponse`.
let process_instance_key = 2251799813687287;

let canceled = client
    .cancel_process_instance()
    .with_process_instance_key(process_instance_key)
    .send()
    .await?;
Source

pub fn set_variables(&self) -> SetVariablesBuilder

Updates all the variables of a particular scope (e.g. process instance, flow element instance) from the given JSON document.

§Examples
use serde_json::json;

let client = zeebe::Client::new();

// process instance key, e.g. from a `CreateProcessInstanceResponse`.
let element_instance_key = 2251799813687287;

let set_variables = client
    .set_variables()
    .with_element_instance_key(element_instance_key)
    .with_variables(json!({"myNewKey": "myValue"}))
    .send()
    .await?;
Source

pub fn job_worker(&self) -> JobWorkerBuilder

Create a new job worker builder.

§Examples
use zeebe::{Client, Job};
let client = Client::new();

client
    .job_worker()
    .with_job_type("my-service")
    .with_handler(handle_job)
    .run()
    .await?;

// job handler function
async fn handle_job(client: Client, job: Job) {
    // processing work...

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

pub fn complete_job(&self) -> CompleteJobBuilder

Completes a job with the given payload, which allows completing the associated service task.

§Examples
let client = zeebe::Client::new();

// typically obtained from `job.key()`;
let job_key = 2251799813687287;

let completed_job = client
    .complete_job()
    .with_job_key(job_key)
    .send()
    .await?;
Source

pub fn fail_job(&self) -> FailJobBuilder

Marks the job as failed.

If the retries argument is positive, then the job will be immediately activatable again, and a worker could try again to process it. If it is zero or negative however, an incident will be raised, tagged with the given error_message, and the job will not be activatable until the incident is resolved.

§Examples
let client = zeebe::Client::new();

// typically obtained from `job.key()`;
let job_key = 2251799813687287;

let failed_job = client
    .fail_job()
    .with_job_key(job_key)
    .with_error_message("something went wrong.")
    .send()
    .await?;
Source

pub fn update_job_retries(&self) -> UpdateJobRetriesBuilder

Updates the number of retries a job has left.

This is mostly useful for jobs that have run out of retries, should the underlying problem be solved.

§Examples
let client = zeebe::Client::new();

// typically obtained from `job.key()`;
let job_key = 2251799813687287;

let updated = client
    .update_job_retries()
    .with_job_key(job_key)
    .with_retries(2)
    .send()
    .await?;
Source

pub fn throw_error(&self) -> ThrowErrorBuilder

Throw an error to indicate that a business error has occurred while processing the job.

The error is identified by an error code and is handled by an error catch event in the process with the same error code.

§Examples
let client = zeebe::Client::new();

// typically obtained from `job.key()`;
let job_key = 2251799813687287;

let error = client
    .throw_error()
    .with_job_key(job_key)
    .with_error_message("something went wrong")
    .with_error_code("E2505")
    .send()
    .await?;
Source

pub fn publish_message(&self) -> PublishMessageBuilder

Publishes a single message. Messages are published to specific partitions computed from their correlation keys.

§Examples
use serde_json::json;

let client = zeebe::Client::new();

let message = client
    .publish_message()
    .with_name("myEvent")
    .with_variables(json!({"someKey": "someValue"}))
    .send()
    .await?;
Source

pub fn resolve_incident(&self) -> ResolveIncidentBuilder

Resolves a given incident.

This simply marks the incident as resolved; most likely a call to update_job_retries will be necessary to actually resolve the problem, followed by this call.

§Examples
let client = zeebe::Client::new();

let incident_key = 2251799813687287;

let resolved = client
    .resolve_incident()
    .with_incident_key(incident_key)
    .send()
    .await?;

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !Send for Client

§

impl !Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T