From 5d007caf2a8f1eb72a56762fa1db44444d496b3d Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Mon, 6 May 2024 13:18:27 +0200 Subject: [PATCH 1/7] Release async-nats/v0.35.0 # 0.35.0 ## Overview This release makes tls setup more flexible, leveraging rusls v0.23 and allowing to pick crypto backend: * ring * aws-lc-rs * fips Some other highlights: * force reconnect via `force_reconnect` method * explicit create/update consumer API Thank you for all your contributions! ## Added * Add `ToServerAddrs` impl for array/vector of strings by @mmalek in https://github.com/nats-io/nats.rs/pull/1231 * Add public constructor for Acker by @AbstractiveNord in https://github.com/nats-io/nats.rs/pull/1232 * Add force reconnect by @Jarema in https://github.com/nats-io/nats.rs/pull/1240 * Add features check by @Jarema in https://github.com/nats-io/nats.rs/pull/1247 * Add stream placement by @Jarema in https://github.com/nats-io/nats.rs/pull/1250 * Add consumer action by @Jarema in https://github.com/nats-io/nats.rs/pull/1254 * Add support for aws-lc-rs (rustls v0.23.0) by @paolobarbolini in https://github.com/nats-io/nats.rs/pull/1222 ## Fixed * Use last header value for JetStream messages by @Jarema in https://github.com/nats-io/nats.rs/pull/1239 ## Changed * Wrap inbox prefix in an `Arc` by @thomastaylor312 in https://github.com/nats-io/nats.rs/pull/1236 * Document feature flags by @Jarema in https://github.com/nats-io/nats.rs/pull/1246 * Don't force flush if write buffer isn't empty by @paolobarbolini in https://github.com/nats-io/nats.rs/pull/1241 ## New Contributors * @mmalek made their first contribution in https://github.com/nats-io/nats.rs/pull/1231 **Full Changelog**: https://github.com/nats-io/nats.rs/compare/async-nats/v0.34.0...async-nats/v0.35.0 Signed-off-by: Tomasz Pietrek Co-authored-by: Piotr Piotrowski --- async-nats/CHANGELOG.md | 38 ++++++++++++++++++++++++++++++++++++++ async-nats/Cargo.toml | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/async-nats/CHANGELOG.md b/async-nats/CHANGELOG.md index 2547bccb7..801b6498c 100644 --- a/async-nats/CHANGELOG.md +++ b/async-nats/CHANGELOG.md @@ -1,3 +1,41 @@ +# 0.35.0 + +## Overview + +This release makes tls setup more flexible, leveraging rustls v0.23 and allowing to pick crypto backend: +* ring +* aws-lc-rs +* fips + +Some other highlights: +* force reconnect via `force_reconnect` method +* explicit create/update consumer API + +Thank you for all your contributions! + +## Added +* Add `ToServerAddrs` impl for array/vector of strings by @mmalek in https://github.com/nats-io/nats.rs/pull/1231 +* Add public constructor for Acker by @AbstractiveNord in https://github.com/nats-io/nats.rs/pull/1232 +* Add force reconnect by @Jarema in https://github.com/nats-io/nats.rs/pull/1240 +* Add features check by @Jarema in https://github.com/nats-io/nats.rs/pull/1247 +* Add stream placement by @Jarema in https://github.com/nats-io/nats.rs/pull/1250 +* Add consumer action by @Jarema in https://github.com/nats-io/nats.rs/pull/1254 +* Add support for aws-lc-rs (rustls v0.23.0) by @paolobarbolini in https://github.com/nats-io/nats.rs/pull/1222 + +## Fixed +* Use last header value for JetStream messages by @Jarema in https://github.com/nats-io/nats.rs/pull/1239 + +## Changed +* Wrap inbox prefix in an `Arc` by @thomastaylor312 in https://github.com/nats-io/nats.rs/pull/1236 +* Document feature flags by @Jarema in https://github.com/nats-io/nats.rs/pull/1246 +* Don't force flush if write buffer isn't empty by @paolobarbolini in https://github.com/nats-io/nats.rs/pull/1241 + +## New Contributors +* @mmalek made their first contribution in https://github.com/nats-io/nats.rs/pull/1231 + +**Full Changelog**: https://github.com/nats-io/nats.rs/compare/async-nats/v0.34.0...async-nats/v0.35.0 + + # 0.34.0 ## Overview diff --git a/async-nats/Cargo.toml b/async-nats/Cargo.toml index 12526fc16..557e7e43e 100644 --- a/async-nats/Cargo.toml +++ b/async-nats/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "async-nats" authors = ["Tomasz Pietrek ", "Casper Beyer "] -version = "0.34.0" +version = "0.35.0" edition = "2021" rust = "1.67.0" description = "A async Rust NATS client" From c182230750d9634b79761b8bb5909d1087da42fc Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Fri, 10 May 2024 06:40:01 -0700 Subject: [PATCH 2/7] Fix docs.rs build The docs.rs build is failing because of the fact, that the `fips` dependency while compiling, tries to write some files, which is not allowed in read-only docs.rs environment. Signed-off-by: Tomasz Pietrek --- async-nats/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/async-nats/Cargo.toml b/async-nats/Cargo.toml index 557e7e43e..e315cb2a2 100644 --- a/async-nats/Cargo.toml +++ b/async-nats/Cargo.toml @@ -83,5 +83,6 @@ harness = false lto = true [package.metadata.docs.rs] -all-features = true +# We can't use `all-features` because the `fips` doesn't compile in restricted docs.rs environment. +features = ["server_2_10", "service", "experimental", "ring", "aws-lc-rs"] rustdoc-args = ["--cfg", "docsrs"] From d8b59e0aafdd3ccbc5f7aed9650bfcac5ac04d64 Mon Sep 17 00:00:00 2001 From: Oscar Cowdery Lack Date: Fri, 10 May 2024 10:35:49 +1000 Subject: [PATCH 3/7] Preserve case of server error messages Server errors can contain case-sensitive values like subject names which can cause confusion if not displayed in their original case. --- async-nats/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/async-nats/src/lib.rs b/async-nats/src/lib.rs index 9ec867c72..34cf05136 100755 --- a/async-nats/src/lib.rs +++ b/async-nats/src/lib.rs @@ -1294,7 +1294,8 @@ impl ServerError { fn new(error: String) -> ServerError { match error.to_lowercase().as_str() { "authorization violation" => ServerError::AuthorizationViolation, - other => ServerError::Other(other.to_string()), + // error messages can contain case-sensitive values which should be preserved + _ => ServerError::Other(error), } } } From 66e8f9955bcc1417bf06a0c63e082added86ee68 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Mon, 13 May 2024 18:25:30 +0200 Subject: [PATCH 4/7] Release v0.35.1 Signed-off-by: Tomasz Pietrek --- async-nats/CHANGELOG.md | 12 ++++++++++++ async-nats/Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/async-nats/CHANGELOG.md b/async-nats/CHANGELOG.md index 801b6498c..ee30690f3 100644 --- a/async-nats/CHANGELOG.md +++ b/async-nats/CHANGELOG.md @@ -1,3 +1,15 @@ +# 0.35.1 +## Overview + +This release fixes broken docs build caused by `fips`, which cannot be built in restricted docs.rs environment. + +## What's Changed +* Fix docs.rs build by @Jarema in https://github.com/nats-io/nats.rs/pull/1259 +* Preserve case of server error messages by @oscarwcl in https://github.com/nats-io/nats.rs/pull/1258 + + +**Full Changelog**: https://github.com/nats-io/nats.rs/compare/async-nats/v0.35.0...async-nats/v0.35.1 + # 0.35.0 ## Overview diff --git a/async-nats/Cargo.toml b/async-nats/Cargo.toml index e315cb2a2..d61882ea9 100644 --- a/async-nats/Cargo.toml +++ b/async-nats/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "async-nats" authors = ["Tomasz Pietrek ", "Casper Beyer "] -version = "0.35.0" +version = "0.35.1" edition = "2021" rust = "1.67.0" description = "A async Rust NATS client" From 0088b85b15e317f1a50f1f7e820a7d65264e6cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Corr=C3=AAa?= <75134774+HeCorr@users.noreply.github.com> Date: Mon, 20 May 2024 06:57:23 -0300 Subject: [PATCH 5/7] Add `client.flush()` calls to example code in docs --- async-nats/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/async-nats/src/lib.rs b/async-nats/src/lib.rs index 34cf05136..f6e20a527 100755 --- a/async-nats/src/lib.rs +++ b/async-nats/src/lib.rs @@ -84,6 +84,10 @@ //! for _ in 0..10 { //! client.publish(subject, data.clone()).await?; //! } +//! +//! // Flush internal buffer before exiting to make sure all messages are sent +//! client.flush().await?; +//! //! # Ok(()) //! # } //! ``` From 954040757519fc3508ce3f33318ae4e09c0b58b2 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Mon, 20 May 2024 13:08:29 +0200 Subject: [PATCH 6/7] Removes dead code carried over from the old client Signed-off-by: Tomasz Pietrek --- async-nats/src/options.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/async-nats/src/options.rs b/async-nats/src/options.rs index 46c9c0a1a..2d5c2bb8d 100644 --- a/async-nats/src/options.rs +++ b/async-nats/src/options.rs @@ -42,12 +42,9 @@ use tokio_rustls::rustls; /// # } /// ``` pub struct ConnectOptions { - // pub(crate) auth: AuthStyle, pub(crate) name: Option, pub(crate) no_echo: bool, - pub(crate) retry_on_failed_connect: bool, pub(crate) max_reconnects: Option, - pub(crate) reconnect_buffer_size: usize, pub(crate) connection_timeout: Duration, pub(crate) auth: Auth, pub(crate) tls_required: bool, @@ -75,8 +72,6 @@ impl fmt::Debug for ConnectOptions { f.debug_map() .entry(&"name", &self.name) .entry(&"no_echo", &self.no_echo) - .entry(&"retry_on_failed_connect", &self.retry_on_failed_connect) - .entry(&"reconnect_buffer_size", &self.reconnect_buffer_size) .entry(&"max_reconnects", &self.max_reconnects) .entry(&"connection_timeout", &self.connection_timeout) .entry(&"tls_required", &self.tls_required) @@ -88,7 +83,7 @@ impl fmt::Debug for ConnectOptions { .entry(&"ping_interval", &self.ping_interval) .entry(&"sender_capacity", &self.sender_capacity) .entry(&"inbox_prefix", &self.inbox_prefix) - .entry(&"retry_on_initial_connect", &self.retry_on_failed_connect) + .entry(&"retry_on_initial_connect", &self.retry_on_initial_connect) .entry(&"read_buffer_capacity", &self.read_buffer_capacity) .finish() } @@ -99,8 +94,6 @@ impl Default for ConnectOptions { ConnectOptions { name: None, no_echo: false, - retry_on_failed_connect: false, - reconnect_buffer_size: 8 * 1024 * 1024, max_reconnects: None, connection_timeout: Duration::from_secs(5), tls_required: false, From ec6331cb05b81e6b3c41bd75762ddab18f256ecd Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Mon, 20 May 2024 14:30:42 +0200 Subject: [PATCH 7/7] Improve ack test Signed-off-by: Tomasz Pietrek --- async-nats/tests/jetstream_tests.rs | 47 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/async-nats/tests/jetstream_tests.rs b/async-nats/tests/jetstream_tests.rs index 0f56c5c30..2e007c95a 100755 --- a/async-nats/tests/jetstream_tests.rs +++ b/async-nats/tests/jetstream_tests.rs @@ -2378,10 +2378,18 @@ mod jetstream { let mut iter = consumer.fetch().max_messages(100).messages().await.unwrap(); client.flush().await.unwrap(); - // TODO: when rtt() is available, use it here. - tokio::time::sleep(Duration::from_millis(400)).await; - let info = consumer.info().await.unwrap(); - assert_eq!(info.num_ack_pending, 10); + tryhard::retry_fn(|| async { + let mut consumer = consumer.clone(); + let num_ack_pending = consumer.info().await?.num_ack_pending; + if num_ack_pending != 10 { + return Err(format!("expected {}, got {}", 10, num_ack_pending).into()); + } + Ok::<(), async_nats::Error>(()) + }) + .retries(10) + .exponential_backoff(Duration::from_millis(500)) + .await + .unwrap(); // standard ack if let Some(message) = iter.next().await { @@ -2389,19 +2397,36 @@ mod jetstream { } client.flush().await.unwrap(); - tokio::time::sleep(Duration::from_millis(100)).await; - let info = consumer.info().await.unwrap(); - assert_eq!(info.num_ack_pending, 9); + tryhard::retry_fn(|| async { + let mut consumer = consumer.clone(); + let num_ack_pending = consumer.info().await?.num_ack_pending; + if num_ack_pending != 9 { + return Err(format!("expected {}, got {}", 9, num_ack_pending).into()); + } + Ok::<(), async_nats::Error>(()) + }) + .retries(10) + .exponential_backoff(Duration::from_millis(500)) + .await + .unwrap(); // double ack if let Some(message) = iter.next().await { message.unwrap().double_ack().await.unwrap(); } - client.flush().await.unwrap(); - tokio::time::sleep(Duration::from_millis(500)).await; - let info = consumer.info().await.unwrap(); - assert_eq!(info.num_ack_pending, 8); + tryhard::retry_fn(|| async { + let mut consumer = consumer.clone(); + let num_ack_pending = consumer.info().await?.num_ack_pending; + if num_ack_pending != 8 { + return Err(format!("expected {}, got {}", 8, num_ack_pending).into()); + } + Ok::<(), async_nats::Error>(()) + }) + .retries(10) + .exponential_backoff(Duration::from_millis(500)) + .await + .unwrap(); // in progress if let Some(message) = iter.next().await {