-
Notifications
You must be signed in to change notification settings - Fork 590
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
feat(source): add NATS source consumer parameters #17615
Changes from 2 commits
90a675b
742c4db
25494aa
d5f0858
f54cc24
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ use std::io::Write; | |
use std::time::Duration; | ||
|
||
use anyhow::{anyhow, Context}; | ||
use async_nats::jetstream::consumer::DeliverPolicy; | ||
use async_nats::jetstream::consumer::{AckPolicy, DeliverPolicy, ReplayPolicy}; | ||
use async_nats::jetstream::{self}; | ||
use aws_sdk_kinesis::Client as KinesisClient; | ||
use pulsar::authentication::oauth2::{OAuth2Authentication, OAuth2Params}; | ||
|
@@ -639,6 +639,26 @@ impl NatsCommon { | |
stream: String, | ||
split_id: String, | ||
start_sequence: NatsOffset, | ||
durable_name: Option<String>, | ||
description: Option<String>, | ||
ack_policy: Option<String>, | ||
ack_wait: Option<Duration>, | ||
max_deliver: Option<i64>, | ||
filter_subject: Option<String>, | ||
filter_subjects: Option<Vec<String>>, | ||
replay_policy: Option<String>, | ||
rate_limit: Option<u64>, | ||
sample_frequency: Option<u8>, | ||
max_waiting: Option<i64>, | ||
max_ack_pending: Option<i64>, | ||
_idle_heartbeat: Option<Duration>, | ||
max_batch: Option<i64>, | ||
max_bytes: Option<i64>, | ||
max_expires: Option<Duration>, | ||
inactive_threshold: Option<Duration>, | ||
num_replicas: Option<usize>, | ||
memory_storage: Option<bool>, | ||
backoff: Option<Vec<Duration>>, | ||
) -> ConnectorResult< | ||
async_nats::jetstream::consumer::Consumer<async_nats::jetstream::consumer::pull::Config>, | ||
> { | ||
|
@@ -650,7 +670,24 @@ impl NatsCommon { | |
.replace(['.', '>', '*', ' ', '\t'], "_"); | ||
let name = format!("risingwave-consumer-{}-{}", subject_name, split_id); | ||
let mut config = jetstream::consumer::pull::Config { | ||
ack_policy: jetstream::consumer::AckPolicy::None, | ||
durable_name, | ||
description, | ||
ack_wait: ack_wait.unwrap_or_default(), | ||
max_deliver: max_deliver.unwrap_or_default(), | ||
filter_subject: filter_subject.unwrap_or_default(), | ||
filter_subjects: filter_subjects.unwrap_or_default(), | ||
rate_limit: rate_limit.unwrap_or_default(), | ||
sample_frequency: sample_frequency.unwrap_or_default(), | ||
max_waiting: max_waiting.unwrap_or_default(), | ||
max_ack_pending: max_ack_pending.unwrap_or_default(), | ||
// idle_heartbeat: idle_heart.unwrap_or_default(), | ||
max_batch: max_batch.unwrap_or_default(), | ||
max_bytes: max_bytes.unwrap_or_default(), | ||
max_expires: max_expires.unwrap_or_default(), | ||
inactive_threshold: inactive_threshold.unwrap_or_default(), | ||
memory_storage: memory_storage.unwrap_or_default(), | ||
backoff: backoff.unwrap_or_default(), | ||
num_replicas: num_replicas.unwrap_or_default(), | ||
..Default::default() | ||
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. These I'm OK with this but we should be aware of the difference. |
||
}; | ||
|
||
|
@@ -671,9 +708,24 @@ impl NatsCommon { | |
}, | ||
NatsOffset::None => DeliverPolicy::All, | ||
}; | ||
|
||
let ack_policy = match ack_policy.as_deref() { | ||
Some("all") => AckPolicy::All, | ||
Some("explicit") => AckPolicy::Explicit, | ||
_ => AckPolicy::None, | ||
}; | ||
|
||
let replay_policy = match replay_policy.as_deref() { | ||
Some("instant") => ReplayPolicy::Instant, | ||
Some("original") => ReplayPolicy::Original, | ||
_ => ReplayPolicy::Instant, | ||
}; | ||
|
||
let consumer = stream | ||
.get_or_create_consumer(&name, { | ||
config.deliver_policy = deliver_policy; | ||
config.ack_policy = ack_policy; | ||
config.replay_policy = replay_policy; | ||
config | ||
}) | ||
.await?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::time::Duration; | ||
|
||
use anyhow::Context as _; | ||
use async_nats::jetstream::consumer; | ||
use async_trait::async_trait; | ||
|
@@ -85,8 +87,81 @@ impl SplitReader for NatsSplitReader { | |
properties.stream.clone(), | ||
split_id.to_string(), | ||
start_position.clone(), | ||
properties.durable_name.clone(), | ||
properties.description.clone(), | ||
properties.ack_policy.clone(), | ||
properties.ack_wait.clone().map(|s| { | ||
Duration::from_secs(s.parse::<u64>().expect("failed to parse ack_wait to u64")) | ||
}), | ||
properties.max_deliver.clone().map(|s| { | ||
s.parse::<i64>() | ||
.expect("failed to parse max_deliver to i64") | ||
}), | ||
properties.filter_subject.clone(), | ||
properties | ||
.filter_subjects | ||
.clone() | ||
.map(|s| s.split(',').map(|s| s.to_string()).collect()), | ||
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. These don't look good. We'd better use typed properties, and parse the config when creating the properties struct. e.g., using 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. Ah indeed that seems much better, even without understanding the error related to config parsing that parsing seemed a bit sketchy. I’ll give it a try in the upcoming days @xxchan thank you 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. I've moved the consumer specific parameters into a separate struct, and added some typed properties based on @xxchan's suggestion |
||
properties.replay_policy.clone(), | ||
properties | ||
.rate_limit | ||
.clone() | ||
.map(|s| s.parse::<u64>().expect("failed to parse rate_limit to u64")), | ||
properties.sample_frequency.clone().map(|s| { | ||
s.parse::<u8>() | ||
.expect("failed to parse sample_frequency to u8") | ||
}), | ||
properties.max_waiting.clone().map(|s| { | ||
s.parse::<i64>() | ||
.expect("failed to parse max_waiting to i64") | ||
}), | ||
properties.max_ack_pending.clone().map(|s| { | ||
s.parse::<i64>() | ||
.expect("failed to parse max_ack_pending to i64") | ||
}), | ||
properties.idle_heartbeat.clone().map(|s| { | ||
Duration::from_secs( | ||
s.parse::<u64>() | ||
.expect("failed to parse idle_heartbeat to u64"), | ||
) | ||
}), | ||
properties | ||
.max_batch | ||
.clone() | ||
.map(|s| s.parse::<i64>().expect("failed to parse max_batch to i64")), | ||
properties | ||
.max_bytes | ||
.clone() | ||
.map(|s| s.parse::<i64>().expect("failed to parse max_bytes to i64")), | ||
properties.max_expires.clone().map(|s| { | ||
Duration::from_secs(s.parse::<u64>().expect("failed to parse ack_wait to u64")) | ||
}), | ||
properties.inactive_threshold.clone().map(|s| { | ||
Duration::from_secs( | ||
s.parse::<u64>() | ||
.expect("failed to parse inactive_threshold to u64"), | ||
) | ||
}), | ||
properties.num_replicas.clone().map(|s| { | ||
s.parse::<usize>() | ||
.expect("failed to parse num_replicas to usize") | ||
}), | ||
properties.memory_storage.clone().map(|s| { | ||
s.parse::<bool>() | ||
.expect("failed to parse memory_storage to bool") | ||
}), | ||
properties.backoff.clone().map(|s| { | ||
s.split(',') | ||
.map(|s| { | ||
Duration::from_secs( | ||
s.parse::<u64>().expect("failed to parse backoff to u64"), | ||
) | ||
}) | ||
.collect() | ||
}), | ||
) | ||
.await?; | ||
|
||
Ok(Self { | ||
consumer, | ||
properties, | ||
|
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.
Is this deprecated? May just remove it.
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.
Well the behavior of the missed idle heartbeat is a bit cryptic with the ‘async_nats’ crate and is a relatively important parameter user because it translates into error messages sent by the stream in the form of “missed idle heartbeat”, which can cause pipelines to fail. Not sure how to handle this one tbh
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.
Removed from the configuration, since it doesn't exist in the pull consumer config: https://docs.rs/async-nats/latest/async_nats/jetstream/consumer/pull/struct.Config.html