Skip to content
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

Remove server version validation #1273

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .config/nats.dic
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ update_consumer
update_consumer_on_stream
create_consumer_strict
create_consumer_strict_on_stream
leafnodes
9 changes: 8 additions & 1 deletion async-nats/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ impl Client {

/// Returns true if the server version is compatible with the version components.
///
/// This has to be used with caution, as it is not guaranteed that the server
/// that client is connected to is the same version that the one that is
/// a JetStream meta/stream/consumer leader, especially across leafnodes.
///
/// # Examples
///
/// ```no_run
Expand All @@ -128,7 +132,10 @@ impl Client {
pub fn is_server_compatible(&self, major: i64, minor: i64, patch: i64) -> bool {
let info = self.server_info();

let server_version_captures = VERSION_RE.captures(&info.version).unwrap();
let server_version_captures = match VERSION_RE.captures(&info.version) {
Some(captures) => captures,
None => return false,
};

let server_major = server_version_captures
.get(1)
Expand Down
35 changes: 10 additions & 25 deletions async-nats/src/jetstream/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,32 +1003,17 @@ impl Context {
let config = config.into_consumer_config();

let subject = {
if self.client.is_server_compatible(2, 9, 0) {
let filter = if config.filter_subject.is_empty() {
"".to_string()
} else {
format!(".{}", config.filter_subject)
};
config
.name
.as_ref()
.or(config.durable_name.as_ref())
.map(|name| format!("CONSUMER.CREATE.{}.{}{}", stream.as_ref(), name, filter))
.unwrap_or_else(|| format!("CONSUMER.CREATE.{}", stream.as_ref()))
} else if config.name.is_some() {
return Err(ConsumerError::with_source(
ConsumerErrorKind::Other,
"can't use consumer name with server < 2.9.0",
));
} else if let Some(ref durable_name) = config.durable_name {
format!(
"CONSUMER.DURABLE.CREATE.{}.{}",
stream.as_ref(),
durable_name
)
let filter = if config.filter_subject.is_empty() {
"".to_string()
} else {
format!("CONSUMER.CREATE.{}", stream.as_ref())
}
format!(".{}", config.filter_subject)
};
config
.name
.as_ref()
.or(config.durable_name.as_ref())
.map(|name| format!("CONSUMER.CREATE.{}.{}{}", stream.as_ref(), name, filter))
.unwrap_or_else(|| format!("CONSUMER.CREATE.{}", stream.as_ref()))
};

match self
Expand Down
21 changes: 21 additions & 0 deletions async-nats/tests/jetstream_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3633,4 +3633,25 @@ mod jetstream {

assert_eq!(err.kind(), ConsumerUpdateErrorKind::DoesNotExist);
}

#[tokio::test]
async fn test_version_on_initial_connect() {
let client = async_nats::ConnectOptions::new()
.retry_on_initial_connect()
.connect("nats://localhost:4222")
.await
.unwrap();
let jetstream = async_nats::jetstream::new(client.clone());

jetstream
.create_consumer_on_stream(
consumer::pull::Config {
durable_name: Some("name".to_string()),
..Default::default()
},
"events",
)
.await
.expect_err("should fail but not panic because of lack of server info");
}
}
Loading