jetstream
ModuleJetStream: 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;pub struct JetStreamA JetStream context: the API prefix of an account or domain.
Its calls take the Connection to send on.
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;pub struct PublishMessageOne message of JetStream::publish_many.
use utopia_nats::jetstream::PublishOptions;pub struct PublishOptionsThe headers and expectations of a JetStream publish.
use utopia_nats::jetstream::Ttl;pub enum TtlA per-message TTL (Nats-TTL): seconds, or a duration the server parses
("1s", "never").
jetstream::config
Own pageStream and consumer configuration, as the JetStream API reads and writes it.
use utopia_nats::jetstream::config::ConsumerConfig;pub struct ConsumerConfigA consumer's configuration. Durations are in seconds.
use utopia_nats::jetstream::config::ConsumerLimits;pub struct ConsumerLimitsLimits a stream sets on its consumers.
use utopia_nats::jetstream::config::ExternalStream;pub struct ExternalStreamA stream in another account or domain.
use utopia_nats::jetstream::config::Placement;pub struct PlacementWhere a stream's replicas are placed.
use utopia_nats::jetstream::config::Republish;pub struct RepublishRepublishes stored messages to another subject.
use utopia_nats::jetstream::config::StreamConfig;pub struct StreamConfigA stream's configuration. Durations are in seconds (the API's nanoseconds on the wire).
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;pub struct StreamSourceA stream a mirror copies, or one of the streams a stream sources.
use utopia_nats::jetstream::config::SubjectTransform;pub struct SubjectTransformRewrites subjects as messages are stored.
use utopia_nats::jetstream::config::nanos_to_seconds;pub fn nanos_to_seconds(nanos: i64) -> f64The API's nanoseconds to seconds.
use utopia_nats::jetstream::config::seconds_to_nanos;pub fn seconds_to_nanos(seconds: f64) -> i64Seconds to the nanoseconds the API takes, truncated.
jetstream::consumer
Own pageStreams, consumers and the messages they deliver.
use utopia_nats::jetstream::consumer::Consumer;pub struct ConsumerA pull consumer.
use utopia_nats::jetstream::consumer::JetStreamMessage;pub struct JetStreamMessageA message delivered by a JetStream consumer, to acknowledge.
use utopia_nats::jetstream::consumer::MessageBatch;pub struct MessageBatchThe messages one pull returned.
IntoIterator.use utopia_nats::jetstream::consumer::OrderedConsumer;pub struct OrderedConsumerAn 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;pub struct PushSubscriptionA 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;pub struct StreamA stream, with the info it was fetched with.
use utopia_nats::jetstream::consumer::AckKind;pub enum AckKindHow a JetStream message is answered.
pub type PushCallback = Box<dyn FnMut(JetStreamMessage) -> Result<(), CallbackError> + Send>A callback receiving the messages of a push consumer.
jetstream::info
Own pageWhat the JetStream API reports: stream and consumer state, account usage, acknowledgements, stored messages and errors.
use utopia_nats::jetstream::info::AccountInfo;pub struct AccountInfoThe account's JetStream usage and limits.
use utopia_nats::jetstream::info::ApiError;pub struct ApiErrorAn error the JetStream API answered with.
use utopia_nats::jetstream::info::ConsumerInfo;pub struct ConsumerInfoA consumer's configuration and progress.
use utopia_nats::jetstream::info::MsgMetadata;pub struct MsgMetadataWhat a JetStream message's reply subject says about it.
use utopia_nats::jetstream::info::PubAck;pub struct PubAckThe acknowledgement of a JetStream publish.
use utopia_nats::jetstream::info::SequenceInfo;pub struct SequenceInfoA consumer and stream position.
use utopia_nats::jetstream::info::StreamInfo;pub struct StreamInfoA stream's configuration, state and creation time.
use utopia_nats::jetstream::info::StreamMessage;pub struct StreamMessageA message read from a stream by sequence or subject.
use utopia_nats::jetstream::info::StreamState;pub struct StreamStateA stream's message and consumer counts.