Skip to content

Commit e0a6550

Browse files
committed
feat: allow specifying the maximum number of messages to fetch
1 parent 5881b53 commit e0a6550

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

examples/long_lived.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl FromPubSubMessage for UpdatePacket {
2626
fn schedule_pubsub_pull(subscription: Arc<Subscription>) {
2727
task::spawn(async move {
2828
while subscription.client().is_running() {
29-
match subscription.get_messages::<UpdatePacket>().await {
29+
match subscription.get_messages::<UpdatePacket>(100).await {
3030
Ok(messages) => {
3131
for (result, ack_id) in messages {
3232
match result {

examples/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async fn main() {
4040
};
4141

4242
let order_sub = Arc::new(pubsub.subscribe(config.pubsub_subscription));
43-
match order_sub.clone().get_messages::<UpdatePacket>().await {
43+
match order_sub.clone().get_messages::<UpdatePacket>(100).await {
4444
Ok(packets) => {
4545
for packet in &packets {
4646
println!("Received: {:?}", packet);

examples/singleshot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async fn main() {
3737
};
3838

3939
let subscription = Arc::new(pubsub.subscribe(config.pubsub_subscription));
40-
match subscription.get_messages::<UpdatePacket>().await {
40+
match subscription.get_messages::<UpdatePacket>(100).await {
4141
Ok(messages) => {
4242
for (result, ack_id) in messages {
4343
match result {

examples/subscribe_to_topic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn main() {
3535
println!("Subscribed to topic with: {}", sub.name);
3636
let packets = sub
3737
.clone()
38-
.get_messages::<UpdatePacket>()
38+
.get_messages::<UpdatePacket>(100)
3939
.await
4040
.expect("Error Checking PubSub");
4141

src/subscription.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl Subscription {
5959

6060
pub async fn get_messages<T: FromPubSubMessage>(
6161
&self,
62+
max_messages: i32,
6263
) -> Result<Vec<(Result<T, error::Error>, String)>, error::Error> {
6364
let client = self
6465
.client
@@ -69,7 +70,7 @@ impl Subscription {
6970
.parse()
7071
.unwrap();
7172

72-
let json = r#"{"maxMessages": 100}"#;
73+
let json = format!("{{\"maxMessages\": {}}}", max_messages);
7374

7475
let mut req = client.request(Method::POST, json);
7576
*req.uri_mut() = uri.clone();

0 commit comments

Comments
 (0)