Skip to content

Commit 5ca484f

Browse files
authored
increase max_bytes for nats stream and ensure stream config is updated (#5)
1 parent 2d2ce58 commit 5ca484f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/utils.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub async fn setup_jetstream(nats_client: &async_nats::Client) -> Result<jetstre
1010
name: "PYTH_PRICE_UPDATES".to_string(),
1111
subjects: vec!["pyth.price.updates".to_string()],
1212
max_age: Duration::from_secs(300),
13-
max_bytes: 1024 * 1024 * 100,
13+
max_bytes: 1024 * 1024 * 4000,
1414
duplicate_window: Duration::from_secs(60),
1515
discard: stream::DiscardPolicy::New,
1616
max_messages_per_subject: 100,
@@ -19,7 +19,19 @@ pub async fn setup_jetstream(nats_client: &async_nats::Client) -> Result<jetstre
1919
..Default::default()
2020
};
2121

22-
jetstream.get_or_create_stream(stream_config).await?;
23-
info!("JetStream stream created or already exists: PYTH_PRICE_UPDATES");
22+
// Try to get the existing stream
23+
match jetstream.get_stream("PYTH_PRICE_UPDATES").await {
24+
Ok(_) => {
25+
// Stream exists, update its configuration
26+
jetstream.update_stream(stream_config).await?;
27+
info!("JetStream stream updated: PYTH_PRICE_UPDATES");
28+
}
29+
Err(_) => {
30+
// Stream doesn't exist, create it
31+
jetstream.create_stream(stream_config).await?;
32+
info!("JetStream stream created: PYTH_PRICE_UPDATES");
33+
}
34+
}
35+
2436
Ok(jetstream)
2537
}

0 commit comments

Comments
 (0)