Rust

jetstream

Module

JetStream: streams, consumers, acknowledged publishes, and the API the key-value and object stores are built on.

Contents

3 submodules, and what the module defines itself.

use utopia_nats::jetstream::JetStream;
Rust
pub struct JetStream

A JetStream context: the API prefix of an account or domain.

Its calls take the Connection to send on.

Rust
use utopia_nats::jetstream::{PublishOptions, StorageType, StreamConfig};
let js = connection.jetstream(None, None);
js.create_stream(&mut connection, &StreamConfig { subjects: vec!["doc.orders.>".into()], storage: StorageType::Memory, ..StreamConfig::new("DOC_ORDERS") }).await?;
let ack = js.publish(&mut connection, "doc.orders.new", b"{}", PublishOptions { msg_id: Some("order-1".into()), ..Default::default() }, 0).await?;
assert_eq!((ack.stream.as_str(), ack.sequence), ("DOC_ORDERS", 1));
js.delete_stream(&mut connection, "DOC_ORDERS").await?;
use utopia_nats::jetstream::PublishMessage;
Rust
pub struct PublishMessage

One message of JetStream::publish_many.

use utopia_nats::jetstream::PublishOptions;
Rust
pub struct PublishOptions

The headers and expectations of a JetStream publish.

use utopia_nats::jetstream::Ttl;
Rust
pub enum Ttl

A per-message TTL (Nats-TTL): seconds, or a duration the server parses ("1s", "never").

jetstream::config

Own page

Stream and consumer configuration, as the JetStream API reads and writes it.

use utopia_nats::jetstream::config::ConsumerConfig;
Rust
pub struct ConsumerConfig

A consumer's configuration. Durations are in seconds.

use utopia_nats::jetstream::config::ConsumerLimits;
Rust
pub struct ConsumerLimits

Limits a stream sets on its consumers.

use utopia_nats::jetstream::config::ExternalStream;
Rust
pub struct ExternalStream

A stream in another account or domain.

use utopia_nats::jetstream::config::Placement;
Rust
pub struct Placement

Where a stream's replicas are placed.

use utopia_nats::jetstream::config::Republish;
Rust
pub struct Republish

Republishes stored messages to another subject.

use utopia_nats::jetstream::config::StreamConfig;
Rust
pub struct StreamConfig

A stream's configuration. Durations are in seconds (the API's nanoseconds on the wire).

Rust
use utopia_nats::jetstream::{StorageType, StreamConfig};

let config = StreamConfig { subjects: vec!["orders.>".into()], storage: StorageType::Memory, max_age: Some(86400.0), ..StreamConfig::new("ORDERS") };
let wire = config.to_value();
assert_eq!(wire["max_age"], 86_400_000_000_000i64);
assert_eq!(StreamConfig::from_value(&wire), config);
use utopia_nats::jetstream::config::StreamSource;
Rust
pub struct StreamSource

A stream a mirror copies, or one of the streams a stream sources.

use utopia_nats::jetstream::config::SubjectTransform;
Rust
pub struct SubjectTransform

Rewrites subjects as messages are stored.

use utopia_nats::jetstream::config::nanos_to_seconds;
Rust
pub fn nanos_to_seconds(nanos: i64) -> f64

The API's nanoseconds to seconds.

use utopia_nats::jetstream::config::seconds_to_nanos;
Rust
pub fn seconds_to_nanos(seconds: f64) -> i64

Seconds to the nanoseconds the API takes, truncated.

jetstream::consumer

Own page

Streams, consumers and the messages they deliver.

use utopia_nats::jetstream::consumer::Consumer;
Rust
pub struct Consumer

A pull consumer.

use utopia_nats::jetstream::consumer::JetStreamMessage;
Rust
pub struct JetStreamMessage

A message delivered by a JetStream consumer, to acknowledge.

use utopia_nats::jetstream::consumer::MessageBatch;
Rust
pub struct MessageBatch

The messages one pull returned.

Also implements IntoIterator.
use utopia_nats::jetstream::consumer::OrderedConsumer;
Rust
pub struct OrderedConsumer

An ordered consumer: an ephemeral push consumer with flow control and heartbeats, delivering in order, and recreated from the next stream sequence when a gap shows.

use utopia_nats::jetstream::consumer::PushSubscription;
Rust
pub struct PushSubscription

A push consumer's subscription: data messages go to the callback, flow-control requests are answered and heartbeats swallowed. Drive it with Connection::wait or Connection::process_message.

use utopia_nats::jetstream::consumer::Stream;
Rust
pub struct Stream

A stream, with the info it was fetched with.

use utopia_nats::jetstream::consumer::AckKind;
Rust
pub enum AckKind

How a JetStream message is answered.

Rust
pub type PushCallback = Box<dyn FnMut(JetStreamMessage) -> Result<(), CallbackError> + Send>

A callback receiving the messages of a push consumer.

jetstream::info

Own page

What the JetStream API reports: stream and consumer state, account usage, acknowledgements, stored messages and errors.

use utopia_nats::jetstream::info::AccountInfo;
Rust
pub struct AccountInfo

The account's JetStream usage and limits.

use utopia_nats::jetstream::info::ApiError;
Rust
pub struct ApiError

An error the JetStream API answered with.

use utopia_nats::jetstream::info::ConsumerInfo;
Rust
pub struct ConsumerInfo

A consumer's configuration and progress.

use utopia_nats::jetstream::info::MsgMetadata;
Rust
pub struct MsgMetadata

What a JetStream message's reply subject says about it.

use utopia_nats::jetstream::info::PubAck;
Rust
pub struct PubAck

The acknowledgement of a JetStream publish.

use utopia_nats::jetstream::info::SequenceInfo;
Rust
pub struct SequenceInfo

A consumer and stream position.

use utopia_nats::jetstream::info::StreamInfo;
Rust
pub struct StreamInfo

A stream's configuration, state and creation time.

use utopia_nats::jetstream::info::StreamMessage;
Rust
pub struct StreamMessage

A message read from a stream by sequence or subject.

use utopia_nats::jetstream::info::StreamState;
Rust
pub struct StreamState

A stream's message and consumer counts.