Skip to main content

Design

The core knows no broker: a broker crate implements its traits and owns every broker-specific setting.

The service, the broker-agnostic core, and broker crates that plug into its traitsYour serviceruststreamBroker crates#[subscriber]handlers#[ruststream::app]builderruntime: routing, dispatch,settlement, publishingcodecs: JSON, CBOR,MessagePack, or nonechosen at compile timefeatures: memory broker,AsyncAPI, metrics,OpenTelemetry, testingBroker, Subscriber,Publisher, sources,policiescapabilities: batches,transactions, requestand reply, seekingruststream-natssubjects, streams,policies, options,mount stepsruststream-rdkafkatopics, groups,policies, options,mount stepsasync-natsrdkafka
The diagram as text
  1. Your service: #[subscriber] handlers; #[ruststream::app] builder
  2. ruststream: runtime: routing, dispatch, settlement, publishing; codecs: JSON, CBOR, MessagePack, or none chosen at compile time; features: memory broker, AsyncAPI, metrics, OpenTelemetry, testing; Broker, Subscriber, Publisher, sources, policies; capabilities: batches, transactions, request and reply, seeking
  3. Broker crates: ruststream-nats subjects, streams, policies, options, mount steps; ruststream-rdkafka topics, groups, policies, options, mount steps
  4. #[subscriber] handlers → runtime: routing, dispatch, settlement, publishing: mounted on
  5. ruststream-nats subjects, streams, policies, options, mount steps → Broker, Subscriber, Publisher, sources, policies: implements
  6. ruststream-rdkafka topics, groups, policies, options, mount steps → capabilities: batches, transactions, request and reply, seeking: implements
  7. ruststream-nats subjects, streams, policies, options, mount steps → async-nats: wraps
  8. ruststream-rdkafka topics, groups, policies, options, mount steps → rdkafka: wraps

The core depends on no broker client. Its required traits are the lifecycle of a connection, a subscriber that is a Stream of deliveries, and a publisher. Batches, transactions, request and reply, seeking and values a delivery already holds are capability traits a broker implements only when its client has them.

A broker crate owns its vocabulary. The descriptor of a subscription form, the policy of a publisher, the per-message settings a publish carries and the mount steps that read the chain's settings all live there. The core has no broker-specific setting and no default for one.

The codec is a type: the codec a mounting names, or the default one the enabled feature selects. A service without a codec feature has no default, and a mounting that needs one does not compile.

The traits, the runtime and each optional layer are crates of their own, and ruststream re-exports them under one set of paths. The compiler holds the layering: the contract crate, ruststream-core, depends on no other crate of the framework. It builds with #![no_std], with an allocator behind its alloc feature and without one, so a device with a heap or with none can depend on it; ruststream turns on its std feature on every target with an operating system. The delivery body (decoding, middleware, the handler, the reply, the settlement) lives in ruststream-runtime, which names no executor. It is generic over a runtime's clock and over the wait on the app's shutdown. ruststream-runtime-tokio runs it on tokio and owns what is tokio's: the app's lifecycle, spawning, the worker pools, the dedicated threads and the signals. Service code that waits calls ruststream::time::sleep, which sleeps on the app's clock, so the test harness moves it with every other timer. A cargo feature of ruststream turns an optional layer on: the memory broker, AsyncAPI, metrics, logging, OpenTelemetry, testing and the command line. Features only add, and none of them changes what another one does.