-
Notifications
You must be signed in to change notification settings - Fork 3
Improve batch publish errors & bump dependencies #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -862,6 +862,8 @@ pub enum BatchPublishErrorKind { | |||||||||
| BatchPublishNotEnabled, | ||||||||||
| /// Batch publish is incomplete and was abandoned | ||||||||||
| BatchPublishIncomplete, | ||||||||||
| /// Server has too many inflight batches (server limit: 50) | ||||||||||
| BatchPublishTooManyInflight, | ||||||||||
| /// Batch uses unsupported headers (Nats-Msg-Id or Nats-Expected-Last-Msg-Id) | ||||||||||
| BatchPublishUnsupportedHeader, | ||||||||||
| /// Other unspecified error | ||||||||||
|
|
@@ -875,6 +877,7 @@ impl BatchPublishErrorKind { | |||||||||
| match error.error_code() { | ||||||||||
| ErrorCode::ATOMIC_PUBLISH_DISABLED => Self::BatchPublishNotEnabled, | ||||||||||
| ErrorCode::ATOMIC_PUBLISH_INCOMPLETE_BATCH => Self::BatchPublishIncomplete, | ||||||||||
| ErrorCode::ATOMIC_PUBLISH_TOO_MANY_INFLIGHT => Self::BatchPublishTooManyInflight, | ||||||||||
| ErrorCode::ATOMIC_PUBLISH_UNSUPPORTED_HEADER => Self::BatchPublishUnsupportedHeader, | ||||||||||
| ErrorCode::ATOMIC_PUBLISH_TOO_LARGE_BATCH => Self::MaxMessagesExceeded, | ||||||||||
| _ => Self::Other, | ||||||||||
|
|
@@ -895,6 +898,9 @@ impl Display for BatchPublishErrorKind { | |||||||||
| Self::BatchPublishIncomplete => { | ||||||||||
| write!(f, "batch publish is incomplete and was abandoned") | ||||||||||
| } | ||||||||||
| Self::BatchPublishTooManyInflight => { | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same hard-coded limit concern as the doc comment above. Suggestion:
Suggested change
|
||||||||||
| write!(f, "server has too many inflight batches (limit: 50)") | ||||||||||
| } | ||||||||||
| Self::BatchPublishUnsupportedHeader => write!( | ||||||||||
| f, | ||||||||||
| "batch uses unsupported headers (Nats-Msg-Id or Nats-Expected-Last-Msg-Id)" | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,23 @@ | |
| //! # } | ||
| //! ``` | ||
| //! | ||
| //! ## Fast Ingest Batch Publishing | ||
| //! | ||
| //! The [batch_publish_fast] module provides high-throughput, non-atomic batch publishing | ||
| //! using JetStream's fast-ingest feature (nats-server 2.14+): | ||
| //! | ||
| //! ```no_run | ||
| //! # use jetstream_extra::batch_publish_fast::FastPublishExt; | ||
| //! # async fn example(client: impl FastPublishExt) -> Result<(), Box<dyn std::error::Error>> { | ||
| //! let mut batch = client.fast_publish().build()?; | ||
| //! for i in 0..1000 { | ||
| //! batch.add("events.data", format!("msg {i}").into()).await?; | ||
| //! } | ||
| //! let ack = batch.commit("events.done", "final".into()).await?; | ||
| //! # Ok(()) | ||
| //! # } | ||
| //! ``` | ||
| //! | ||
| //! ## Batch Fetching | ||
| //! | ||
| //! The [batch_fetch] module provides efficient batch fetching of messages from streams | ||
|
|
@@ -61,6 +78,7 @@ | |
|
|
||
| pub mod batch_fetch; | ||
| pub mod batch_publish; | ||
| pub mod batch_publish_fast; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build-breaking:
|
||
|
|
||
| pub use async_nats::Subject; | ||
| /// Re-exported type returned by Direct Get operation. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,18 +235,21 @@ mod batch_publish_error_tests { | |
| let err = batch.add("test_incomplete.1", "data".into()).await; | ||
|
|
||
| // This might fail either immediately or on commit | ||
| if err.is_err() { | ||
| if let Err(err) = err { | ||
| assert_eq!( | ||
| err.unwrap_err().kind(), | ||
| BatchPublishErrorKind::BatchPublishIncomplete | ||
| err.kind(), | ||
| BatchPublishErrorKind::BatchPublishTooManyInflight | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion flip from |
||
| ); | ||
| } else { | ||
| // If add succeeded, commit should fail | ||
| let err = batch | ||
| .commit("test_incomplete.2", "final".into()) | ||
| .await | ||
| .unwrap_err(); | ||
| assert_eq!(err.kind(), BatchPublishErrorKind::BatchPublishIncomplete); | ||
| assert_eq!( | ||
| err.kind(), | ||
| BatchPublishErrorKind::BatchPublishTooManyInflight | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The server limit of 50 is hard-coded in both the doc comment and the
Displayimpl below. If the NATS server changes this limit in a future release the error message will be stale. Consider either omitting the specific number or noting it as the value at the time of the async-nats 0.48 / nats-server 2.14 release: