pub struct Context { /* private fields */ }
Expand description

A context which can perform jetstream scoped requests.

Implementations§

Publishes jetstream::Message to the Stream without waiting for acknowledgment from the server that the message has been successfully delivered.

Acknowledgment future that can be polled is returned instead.

If the stream does not exist, no responders error will be returned.

Examples

Publish, and after each publish, await for acknowledgment.

let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let ack = jetstream.publish("events".to_string(), "data".into()).await?;
ack.await?;
jetstream.publish("events".to_string(), "data".into())
    .await?
    .await?;

Publish and do not wait for the acknowledgment. Await can be deferred to when needed or ignored entirely.

let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let first_ack = jetstream.publish("events".to_string(), "data".into()).await?;
let second_ack = jetstream.publish("events".to_string(), "data".into()).await?;
first_ack.await?;
second_ack.await?;

Publish a message with headers to a given subject associated with a stream and returns an acknowledgment from the server that the message has been successfully delivered.

If the stream does not exist, no responders error will be returned.

Examples
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let mut headers = async_nats::HeaderMap::new();
headers.append("X-key", "Value");
let ack = jetstream.publish_with_headers("events".to_string(), headers, "data".into()).await?;

Publish a message built by Publish and returns an acknowledgment future.

If the stream does not exist, no responders error will be returned.

Examples
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let ack =
jetstream.send_publish("events".to_string(),
    Publish::build().payload("data".into()).message_id("uuid")
).await?;

Query the server for account information

Create a JetStream Stream with given config and return a handle to it. That handle can be used to manage and use Consumer.

Examples
use async_nats::jetstream::stream::Config;
use async_nats::jetstream::stream::DiscardPolicy;
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let stream = jetstream.create_stream(Config {
    name: "events".to_string(),
    max_messages: 100_000,
    discard: DiscardPolicy::Old,
    ..Default::default()
}).await?;

Checks for Stream existence on the server and returns handle to it. That handle can be used to manage and use Consumer.

Examples
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let stream = jetstream.get_stream("events").await?;

Create a stream with the given configuration on the server if it is not present. Returns a handle to the stream on the server.

Note: This does not validate if the Stream on the server is compatible with the configuration passed in.

Examples
use async_nats::jetstream::stream::Config;
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let stream = jetstream.get_or_create_stream(Config {
    name: "events".to_string(),
    max_messages: 10_000,
    ..Default::default()
}).await?;

Deletes a Stream with a given name.

Examples
use async_nats::jetstream::stream::Config;
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let stream = jetstream.delete_stream("events").await?;

Updates a Stream with a given config. If specific field cannot be updated, error is returned.

Examples
use async_nats::jetstream::stream::Config;
use async_nats::jetstream::stream::DiscardPolicy;
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let stream = jetstream.update_stream(&Config {
    name: "events".to_string(),
    discard: DiscardPolicy::New,
    max_messages: 50_000,
    ..Default::default()
}).await?;

Lists names of all streams for current context.

Examples
use futures::TryStreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let mut names = jetstream.stream_names();
while let Some(stream) = names.try_next().await? {
    println!("stream: {}", stream);
}

Lists all streams info for current context.

Examples
use futures::TryStreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let mut streams = jetstream.streams();
while let Some(stream) = streams.try_next().await? {
    println!("stream: {:?}", stream);
}

Returns an existing key-value bucket.

Examples
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.get_key_value("bucket").await?;

Creates a new key-value bucket.

Examples
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;

Deletes given key-value bucket.

Examples
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;

Send a request to the jetstream JSON API.

This is a low level API used mostly internally, that should be used only in specific cases when this crate API on Consumer or Stream does not provide needed functionality.

Examples
let client = async_nats::connect("localhost:4222").await?;
let jetstream = async_nats::jetstream::new(client);

let response: Response<Info> = jetstream
.request("STREAM.INFO.events".to_string(), &()).await?;

Creates a new object store bucket.

Examples
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.create_object_store(async_nats::jetstream::object_store::Config {
    bucket: "bucket".to_string(),
    ..Default::default()
}).await?;

Creates a new object store bucket.

Examples
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.get_object_store("bucket").await?;

Delete a object store bucket.

Examples
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.delete_object_store("bucket").await?;

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more