Documentation

Rust SDK

Connect Rust services, workers, and tools to Celeris with async Tokio code, and sign credentials on trusted servers.

The Rust SDK brings Celeris to Rust programs: backend services, workers, command-line tools, and desktop applications. It behaves like the JavaScript SDK, with Rust names, async methods on Tokio, and one CelerisError enum.

Each channel connection automatically joins a segment named default. Access it with channel.default_segment(). That stream does not need an explicit subscription. Use additional named segments when you need separate topics. Messaging explains the listener and permission setup.

Two crates

  • useceleris-client (crate useceleris_client) manages connections, messages, subscriptions, and presence.
  • useceleris-server (crate useceleris_server) signs credentials from your application's access decisions. It runs on trusted servers only.
cargo add useceleris-client
cargo add useceleris-server

Or add them to Cargo.toml:

Cargo.toml
[dependencies]
useceleris-client = "1"
useceleris-server = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Add the server crate only where the signing secret can live. It depends on the client for Credentials, CredentialProvider, and CelerisError only. The client does not include signing facilities.

Both crates need Rust 1.88 or newer. The client is async and runs on Tokio. Its WebSocket is tokio-tungstenite, and its TLS is rustls with the system's root certificates. The server signs with the RustCrypto hmac and sha2 crates. The client includes no serializer and no HTTP client. Add the crates that your application needs, such as serde_json or reqwest.

Follow the guides

  1. Connection and lifecycle: obtain credentials, connect, observe state, recover, and clean up.
  2. Messaging: subscribe, publish, receive, and understand delivery.
  3. Payload formats: text, JSON with serde_json, and custom serializers.
  4. Presence: list connections and watch presence events.
  5. Errors and troubleshooting: handle failures where the SDK reports them.
  6. Server-side usage: sign credentials, and connect from a trusted backend.

Read Reconnection and Recovery for the shared explanation of retries, replay, and application reconciliation. Exact signatures live in the Rust client API and Rust server API.

Tasks and futures in brief

  • A Client, its channels, and their segments are cheap to clone and safe to use from many tasks. Each clone of a channel is the same channel.
  • Listeners are closures. The SDK runs them on Tokio's blocking thread pool, one at a time for each channel. They run in the order the events happened, and never under an SDK lock. A slow listener makes delivery slower. It does not make a queue grow, and it does not stop the runtime's worker threads.
  • A listener can call subscribe, cancel, and the listener methods directly. For the async methods (connect, publish, presence_list, and close), start a task with tokio::spawn.
  • Rust cancels an operation when you drop its future. A dropped connect stops the attempt and sets Failed. A dropped publish withdraws a publish that the socket did not start to write. A dropped presence_list frees the query slot. A drop never closes the channel.

Work with SDK values

Timestamps delivered with messages, notices, and presence are i64 Unix-millisecond values. Presence counts are i32 values. Timeouts and replay lookbacks are std::time::Duration values. Received payloads are &[u8] slices, and you publish any value that implements AsRef<[u8]>. Debug shows Credentials as redacted.

Vocabulary

TermMeaning
Channel referenceName of a communication space inside your application
ChannelOwns one connection once connected
SegmentNamed stream carried over that channel's socket
ListenerYour closure for an event. Registration returns a Registration whose remove() removes it
SubscriptionHeld interest in messages or presence. Release it with cancel()
Credential providerYour function that obtains fresh signed access for each connection attempt

We use Google cookies for analytics and for advertising measurement, only if you allow them. Until you choose, Google sets no cookies. Refer to our Cookie Policy.