-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
215 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "nats" | ||
version = "0.16.0" | ||
version = "0.17.0" | ||
description = "A Rust NATS client" | ||
authors = ["Derek Collison <[email protected]>", "Tyler Neely <[email protected]>", "Stjepan Glavina <[email protected]>"] | ||
edition = "2018" | ||
|
@@ -73,6 +73,7 @@ nats_test_server = { path = "nats_test_server" } | |
quicli = "0.4.0" | ||
smol = "1.2.5" | ||
structopt = "0.3.21" | ||
nats_016 = { package = "nats", version = "0.16.0" } | ||
|
||
[[bench]] | ||
name = "nats_bench" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Migration guide to version [0.17.0](https://github.com/nats-io/nats.rs/releases/tag/untagged-964d5dad97c03c4aa6f4) | ||
|
||
Release 0.17.0 among many features introduced a complete rewrite of the JetStream API with a new subscription interface. | ||
|
||
This page is meant to make migration to the new version easier. | ||
|
||
Lot of changes were also made to keep Rust NATS Client better aligned with Reference NATS Client (Go). | ||
|
||
# Introduction of JetStream context | ||
|
||
To make setting `Domain` and `API Prefix` more convinient by setting it once, not for every `JetStream` related operation, `JetStream` struct was introduced. | ||
|
||
This change resulted in having all `JetStream` API being called as `JetStream` methods. That applies to both `JetStream management` and `JetStream API`. | ||
|
||
```rust no_run | ||
fn main() -> std::io::Result<()> { | ||
let nc = nats::connect("demo.nats.io")?; | ||
// create Jetstream context | ||
let js = nats::jetstream::new(nc); | ||
|
||
// JetStream management | ||
js.add_stream("new_stream")?; | ||
|
||
// subscribing to some stream | ||
let subscription = js.subscribe("events")?; | ||
|
||
// publishing to stream | ||
js.publish("some_stream", "message")?; | ||
Ok(()) | ||
} | ||
``` | ||
|
||
# JetStream Management | ||
|
||
`JetStream management` changed mostly because of add `JetStream` context struct. | ||
|
||
Let's take an example of adding new `stream` with pre 0.17.0: | ||
|
||
```rust | ||
fn main() -> std::io::Result<()> { | ||
use nats_016 as nats; | ||
let nc = nats::connect("demo.nats.io")?; | ||
nc.create_stream("stream_one")?; | ||
|
||
// create stream with options | ||
nc.create_stream(nats::jetstream::StreamConfig{ | ||
name: "stream_two".to_string(), | ||
max_msgs: 2000, | ||
discard: nats::jetstream::DiscardPolicy::Old, | ||
..Default::default() | ||
})?; | ||
Ok(()) | ||
} | ||
``` | ||
|
||
And compare it to the new API: | ||
|
||
```rust | ||
fn main() -> std::io::Result<()> { | ||
let nc = nats::connect("demo.nats.io")?; | ||
// Initialize JetStream struct first | ||
let js = nats::jetstream::new(nc); | ||
// use it | ||
js.add_stream("stream_three")?; | ||
|
||
// add stream with options | ||
js.add_stream(nats::jetstream::StreamConfig{ | ||
name: "stream_four".to_string(), | ||
max_msgs: 2000, | ||
discard: nats::jetstream::DiscardPolicy::Old, | ||
..Default::default() | ||
})?; | ||
|
||
Ok(()) | ||
} | ||
``` | ||
|
||
As you can see one more thing changed in `JetStream Management` - `create_stream` was renamed to `add_stream` to keep better aligment with reference client. | ||
|
||
# JetStream API | ||
|
||
JetStream interface was **entirely rewritten**. | ||
Those changes were necessary for both cleanup and preparation for introduction of `Key-Value Store` and `Object Store`. | ||
|
||
Except all methods being moved to `JetStream` struct, their behaviour and API also changed. | ||
|
||
Full example with creating stream, publishing and subscribing with ephemeral subscription: | ||
|
||
|
||
```rust | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
|
||
let nc = nats::connect("demo.nats.io")?; | ||
let js = nats::jetstream::new(nc); | ||
js.add_stream(&nats::jetstream::StreamConfig { | ||
name: "events".to_string(), | ||
subjects: vec![ | ||
"events.>".to_string(), | ||
], | ||
..Default::default() | ||
})?; | ||
js.publish("events.test", "test message")?; | ||
let sub = js.subscribe("events.>")?; | ||
sub.with_handler(move |message| { | ||
println!("received {}", &message); | ||
Ok(()) | ||
}); | ||
js.delete_stream("events")?; | ||
Ok(()) | ||
} | ||
``` | ||
|
||
To see all changes, please check cargo docs and it's examples. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters