Upgrading an existing v4 project? See Upgrading to v5. If you want to
keep Node or Bun as the host and call Rust functions for CPU-heavy work instead, see
Rust Libraries.
Breaking changes
-
Echoes: Kafka was removed. Pulse is the only
event transport, configured as before in
events.pulse:Top-levelclient,producer, andconsumer,events.kafka,events.consumeFrom,events.publishTo, andonMessageare gone, andpublish()no longer takesacks/timeout. Request echoes (/echoes-services) keep the same wire format, so v4 and v5 services can call each other.
The Rust host
All crates are version5.0.0, target Rust edition 2024 (Rust 1.88+), and live in
crates/:
The host is built on tokio (the async runtime), tower
(middleware), and axum (the web framework).
Add a
server/ crate next to your app:
ORION_ENV_FILE_PATH,
ORION_ENV_SECRET_KEY). It listens on http_port / PORT (default 3000) and starts the app with
ORION_HOST=rust, a private unix socket (ORION_HOST_SOCKET), and a per-process secret token
(ORION_HOST_TOKEN). The app keeps running its own jobs and event consumers until you give the host
.jobs(...) or .echoes(...) (with .pulse(...)); from then on the host runs them.
In development, override the worker command with ORION_NODE_COMMAND so the host runs orion dev
instead of the built bundle:
orion dev restarts the worker on every change; the host keeps the port open and requests wait
until the worker is back.
On SIGTERM or SIGINT, the host stops taking new requests, jobs, and events, waits for what is
running (in Rust and in Node), and then stops the worker’s process group (SIGTERM, then SIGKILL
after 10 seconds). If the worker exits by itself, the host exits with an error so your orchestrator
restarts both.
Routes
Rust routes are plain axum routes. Unmatched paths—and unmatched HTTP methods on a path handled by Rust—are forwarded to the Orionjs app, so you can moveGET /items to
Rust while POST /items stays in JS.
Errors answer with the same JSON shape as @orion-js/http, so clients can’t tell where a route
runs:
Error::user(code, message)andError::user_with_extra(code, message, extra)answer400(UserErrorJSON).Error::validation(errors)answers400(ValidationErrorJSON).Error::auth(message)answers401(AuthErrorJSON).Error::internal(message)and anystd::error::Errorconverted with?answer500with the same 10-character SHA-1 hash as@orion-js/http(while logging the underlying message).
Jwt<Claims> extractor validates Authorization: Bearer <token> headers using jwt_secret /
JWT_SECRET (HS256) automatically from the env file, or a custom JwtConfig passed via
App::jwt(...) (JwtConfig::hs256 or JwtConfig::new for RS256, issuer/audience validation,
etc.). Use Option<Jwt<Claims>> when authentication is optional (missing tokens become None;
invalid tokens still return 401).
MongoDB and env
orionrs::env() loads the app’s encrypted env file once (ORION_ENV_FILE_PATH +
ORION_ENV_SECRET_KEY). orionrs::mongo connects with the official mongodb driver and provides
Orionjs-compatible IDs and dates:
Jobs
With.jobs(...), the host schedules every job from orionjs.jobs_dogs_records and
orionjs.jobs_dogs_history. Jobs defined in Rust run in Rust; jobs defined only in the app are
claimed by the host and run in Node, keeping their JS onError, onStale, getNextRun,
executionGuard, canTakeJobs, getJobsFilter, and maxParallelExecutionsPerServer. Call
startWorkers in the app as before: with the host it registers the jobs instead of polling.
job.schedule() or from Rust with scheduler.schedule(...),
scheduler.schedule_named(...), or scheduler.schedule_many(...) run wherever the job is defined.
A job defined in both runs in Rust. Long-running Rust jobs can renew their lock with
context.extend_lock_time(duration).await and check context.is_stale().
Echoes
With.echoes(...), the host answers POST /echoes-services and—when .pulse(...) is
configured—consumes all Pulse events. Echoes defined in Rust run in Rust; the rest are delivered to
the app through echoes.deliver with the same retries and dead letters. If you omit .pulse(...),
the host handles Rust request echoes and forwards other requests while the app keeps consuming its
own Pulse events.
consumerGroup as the app. The requests password is read from echoes_password /
ECHOES_PASSWORD (or set explicitly with .password(...)), and the handler path defaults to
/echoes-services (override with .handler_path(...)). For batch consumers matching
createEchoBatchEvent in JS, use .batch_event(topic, batch_size, EventOptions::default(), handler).
A full example
examples/backend-base
runs a flow across both languages: a Rust route (POST /examples) publishes example.created, a
JS echo schedules the JS job processExample, the host claims and runs it in Node, and it publishes
example.processed, which a Rust echo handles. Its end-to-end tests (bun run e2e) start the real
host binary and Orionjs app.