Photon
Feature flags, wiring, and verify commands for adding Photon to a Rust service. Project overview: README.
Install
crates.io package uf-photon (Rust crate name remains photon):
= { = "uf-photon", = "0.1.1", = ["runtime", "mem"] }
Features
| Feature | Purpose |
|---|---|
runtime |
Full stack — backends, Photon, executor. |
mem |
Default in-process storage (InProcStoragePort) for tests and dev |
sqlite |
Embedded SQLite storage (photon-backend-sqlite) |
nats |
NATS JetStream storage adapter (photon-backend-nats) |
fluvio |
Fluvio storage adapter (photon-backend-fluvio) |
kafka |
Kafka storage adapter (photon-backend-kafka) |
Configuration reference: docs.rs photon::config. Primary tutorial: Getting started (Mode 1 embedded vs Mode 2 brokered publisher/worker).
Ships with no default features (default = []). Enable runtime + mem for the standard evaluation path.
Wiring
Follow the rustdoc Getting started for topology choice. Checklist:
- Build with
Photon::builder()— default installsInProcStoragePort(mem). RequiresPHOTON_TRANSPORT_KEY(TransportCrypto::from_env). - Optionally pass
.storage_port(Arc<dyn StoragePort>)forsqliteor broker adapters (Mode 2: same port config on every binary). - Call
.auto_registry()when using#[photon::topic]/#[photon::subscribe]. - Keep the
Photonhandle and callpublish_on(&photon)/subscribe_on(&photon, opts)(preferred). - Optional:
photon::configure(photon)for process-wide.publish()/.subscribe()sugar. - Call
photon.start_executor(identity)on Mode 1 hosts and Mode 2 workers (publisher-only binaries can skip).
Default bootstrap (mem)
use Photon;
// Loads PHOTON_TRANSPORT_KEY via from_env().
let photon = builder.auto_registry.build?;
// EventType { ... }.publish_on(&photon).await?;
// Optional: configure(photon) for .publish() without a handle.
Custom storage port
use Arc;
use Photon;
use InProcStoragePort;
use TransportCrypto;
let port = new;
let photon = builder
.storage_port
.auto_registry
.build?;
Broker env vars and builder options: each adapter's *StoragePortBuilder rustdoc (linked from photon::config).
SQLite — durable single-process
Write-through persistence with in-memory live fanout (no external broker):
use Arc;
use ;
let port = new;
// Or: SqliteStoragePort::from_env().await? // reads PHOTON_SQLITE_PATH
let photon = builder
.storage_port
.auto_registry
.build?;
NATS JetStream — production (durable)
Durable subscriptions, checkpoint replay, and stream-sharded fleet ingress:
use Arc;
use ;
let port = new;
let photon = builder
.storage_port
.auto_registry
.build?;
NATS JetStream — high ingress (ephemeral)
Maximum publish throughput when durable replay and checkpoints are not required:
use Arc;
use ;
let port = new;
let photon = builder
.storage_port
.auto_registry
.build?;
Builder fields and env fallbacks: NatsStoragePortBuilder rustdoc.
Verify
Prefer AWS when local cargo is unavailable: ../infra/aws/sqlite-smok~/aws/photon-upstream/sqlite-smoke/run-remote-check.sh.
Full matrix: root README § Verify. Macro expansion: docs/macro-expansion.md.