pub struct Client { /* private fields */ }
Expand description
Client used to communicate with Zeebe.
Implementations§
Source§impl Client
impl Client
Sourcepub fn from_config(config: ClientConfig) -> Result<Self>
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,
})?;
Sourcepub async fn auth_initialized(&self) -> Result<()>
pub async fn auth_initialized(&self) -> Result<()>
Future that resolves when the auth interceptor is initialized.
Sourcepub fn topology(&self) -> TopologyBuilder
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?;
Sourcepub fn deploy_process(&self) -> DeployProcessBuilder
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?;
Sourcepub fn create_process_instance(&self) -> CreateProcessInstanceBuilder
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?;
Sourcepub fn create_process_instance_with_result(
&self,
) -> CreateProcessInstanceWithResultBuilder
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?;
Sourcepub fn cancel_process_instance(&self) -> CancelProcessInstanceBuilder
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?;
Sourcepub fn set_variables(&self) -> SetVariablesBuilder
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?;
Sourcepub fn job_worker(&self) -> JobWorkerBuilder
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;
}
Sourcepub fn complete_job(&self) -> CompleteJobBuilder
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?;
Sourcepub fn fail_job(&self) -> FailJobBuilder
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?;
Sourcepub fn update_job_retries(&self) -> UpdateJobRetriesBuilder
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?;
Sourcepub fn throw_error(&self) -> ThrowErrorBuilder
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?;
Sourcepub fn publish_message(&self) -> PublishMessageBuilder
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?;
Sourcepub fn resolve_incident(&self) -> ResolveIncidentBuilder
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request