Crate mcai_worker_sdk

source ·
Expand description

MCAI Worker SDK

This library is an SDK to communicate via message broker with StepFlow. It’s used for every worker as an abstraction. It manage itself requirements, message parsing, direct messaging.

Worker implementation

  1. Create a Rust project
  2. Add MCAI Worker SDK as a dependency in Cargo.toml: mcai_worker_sdk = "^1.0"
  3. Update the main file with the example provided here to implement MessageEvent trait, and call the start_worker to start the worker itself.
use mcai_worker_sdk::prelude::*;
use serde_derive::Deserialize;
use schemars::JsonSchema;

#[derive(Debug)]
struct WorkerNameEvent {}

#[derive(Debug, Deserialize, JsonSchema)]
struct WorkerParameters {}

// For opensource workers
default_rust_mcai_worker_description!();
// Or uncomment one of these lines for licensed workers
// default_rust_mcai_worker_description!(Private);
// default_rust_mcai_worker_description!(Commercial);
// You can also specify the name of your organisation
// default_rust_mcai_worker_description!("My Organisation", Commercial);

impl McaiWorker<WorkerParameters, RustMcaiWorkerDescription> for WorkerNameEvent {
}
static WORKER_NAME_EVENT: WorkerNameEvent = WorkerNameEvent {};

// uncomment it to start the worker
// fn main() {
//   mcai_worker_sdk::start_worker(&WORKER_NAME_EVENT);
// }

Runtime configuration

AMQP connection

VariableDescription
AMQP_HOSTNAMEIP or host of AMQP server (default: localhost)
AMQP_PORTAMQP server port (default: 5672)
AMQP_TLSenable secure connection using AMQPS (default: false, enable with true or 1 or TRUE or True)
AMQP_USERNAMEUsername used to connect to AMQP server (default: guest)
AMQP_PASSWORDPassword used to connect to AMQP server (default: guest)
AMQP_VHOSTAMQP virtual host (default: /)
AMQP_QUEUEAMQP queue name used to receive job orders (default: job_undefined)
AMQP_SERVER_CONFIGURATIONRabbitMP configuration. Either standalone or cluster (default: standalone)

Vault connection

VariableDescription
BACKEND_HOSTNAMEURL used to connect to backend server (default: http://127.0.0.1:4000/api)
BACKEND_USERNAMEUsername used to connect to backend server
BACKEND_PASSWORDPassword used to connect to backend server

Start worker locally

MCAI Worker SDK can be launched locally - without RabbitMQ. It can process some message for different purpose (functional tests, message order examples, etc.).

To start worker in this mode, setup the environment variable SOURCE_ORDERS with path(s) to json orders. It can take multiple orders, joined with : on unix platform, ; on windows os.

Examples:

RUST_LOG=info SOURCE_ORDERS=./examples/success_order.json:./examples/error_order.json cargo run --example worker

Re-exports

Modules

Macros

Enums

Type Aliases