Nexus feature guide - Rust SDK
Nexus is a tool for coordinating asynchronous operations between Temporal and external systems. Service handlers allow Workflows to receive inbound requests through Nexus.
Call a Nexus Operation from a Workflow
You can start a Nexus operation from a Workflow using ctx.start_nexus_operation():
use std::time::Duration;
use temporalio_common::protos::{coresdk::nexus, temporal::api::{common::v1::Payload,}};
use temporalio_macros::{workflow, workflow_methods};
use temporalio_sdk::{NexusOperationOptions, WorkflowContext, WorkflowContextView, WorkflowResult};
#[workflow]
pub struct GreetingWorkflow {
pub name: String,
}
#[workflow_methods]
impl GreetingWorkflow {
#[init]
fn new(_ctx: &WorkflowContextView, name: String) -> Self {
Self { name }
}
#[run]
pub async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
let name = ctx.state(|s| s.name.clone());
let nexus_started = ctx.start_nexus_operation(NexusOperationOptions {
endpoint: "my-endpoint".to_string(),
service: "my-service".to_string(),
operation: "my-operation".to_string(),
input: Some(Payload {
data: name.as_bytes().to_vec(),
..Default::default()
}),
start_to_close_timeout: Some(Duration::from_secs(10)),
..Default::default()
}).await;
let nexus_result = nexus_started.unwrap();
println!("Nexus result: {:?}", nexus_result);
Ok(format!("nexus result: {:?}", nexus_result))
}
}
Nexus Operation Arguments
endpoint- The Nexus endpoint nameservice- The service nameoperation- The operation nameinput- The input payload (optional)start_to_close_timeout- How long the operation can run