Expand description

JetStream stream management and consumers. Support for the JetStream at-least-once messaging system.

Examples

Create a new stream with default options:

let nc = nats::connect("my_server::4222")?;
let js = nats::jetstream::new(nc);

// add_stream converts a str into a
// default `StreamConfig`.
js.add_stream("my_stream")?;

Create a new stream with configuration:

use nats::jetstream::{StreamConfig, StorageType};

let nc = nats::connect("my_server::4222")?;
let js = nats::jetstream::new(nc);

js.add_stream(StreamConfig {
    name: "my_memory_stream".to_string(),
    max_bytes: 5 * 1024 * 1024 * 1024,
    storage: StorageType::Memory,
    ..Default::default()
})?;

Create a new consumer:

let nc = nats::connect("my_server::4222")?;
let js = nats::jetstream::new(nc);

js.add_stream("my_stream")?;
js.add_consumer("my_stream", "my_consumer")?;

Create a new consumer with configuration:

use nats::jetstream::{ ConsumerConfig };
let nc = nats::connect("my_server::4222")?;
let js = nats::jetstream::new(nc);

js.add_stream("my_stream")?;
js.add_consumer("my_stream", ConsumerConfig {
  deliver_subject: Some("my_deliver_subject".to_string()),
  durable_name: Some("my_durable_consumer".to_string()),
  ..Default::default()
})?;

Create a new subscription:

let nc = nats::connect("my_server::4222")?;
let js = nats::jetstream::new(nc);

js.add_stream("my_stream")?;
let subscription = js.subscribe("my_stream")?;

This will attempt to bind to an existing consumer if it exists, otherwise it will create a new internally managed consumer resource that gets destroyed when the subscription is dropped.

Re-exports

pub use crate::jetstream::pull_subscription::PullSubscription;
pub use crate::jetstream::push_subscription::PushSubscription;

Modules

Pull subscriptions

Push subscriptions

Structs

contains info about the JetStream usage from the current account.

Various limits imposed on a particular account.

reports on API calls to JetStream for this account.

Used for next Pull Request for Pull Consumer

Information about the stream’s, consumer’s associated JetStream cluster

Configuration for consumers. From a high level, the durable_name and deliver_subject fields have a particularly strong influence on the consumer’s overall behavior.

Information about a consumer

Error type returned from an API response when an error occurs.

A context for performing JetStream operations.

Information about a received message

JetStream options

An iterator over paged JetStream API operations.

The members of the RAFT cluster

PublishAck is an acknowledgement received after successfully publishing a message.

Options for publishing

Options to configure Pull Subsscription

The payload used to generate a purge request.

The response generated by trying ot purge a stream.

A raw stream message in the representation it is stored.

Information about a consumer and the stream it is consuming

StreamConfig determines the properties for a stream. There are sensible defaults for most. If no subjects are given the name will be used as the only subject.

Shows config and current state for this stream.

A message stored in a stream.

information about the given stream.

Options for subscription

Enums

The kinds of response used for acknowledging a processed message.

Determines whether messages will be acknowledged individually, in batches, or never.

DeliverPolicy determines how the consumer should select the first message to deliver.

DiscardPolicy determines how we proceed when limits of messages or bytes are hit. The default, Old will remove older messages. New will fail to store the new message.

ErrorCode which can be returned from a server an a response when an error occurs.

ReplayPolicy controls whether messages are sent to a consumer as quickly as possible or at the rate that they were originally received at.

RetentionPolicy determines how messages in a set are retained.

determines how messages are stored for retention.

Functions

Creates a new JetStream context using the given Connection and default options.

Type Definitions

A UTC time