From 16c4ec57b99495a8cb5b8983b234efae7d917482 Mon Sep 17 00:00:00 2001 From: vovkman Date: Mon, 4 Dec 2023 16:58:44 -0800 Subject: [PATCH 1/2] update readme and rust example to include client -> server ping --- README.md | 5 +++++ examples/rust/src/bin/client.rs | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5051ebd..433ef5a5 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,11 @@ It's possible to add limits for filters in config. If `filters` field is omitted - [Rust](examples/rust) - [TypeScript](examples/typescript) +**NOTE**: Some load balancers will terminate gRPC connections if there are no messages sent from the client for a period of time. +In order to mitigate this you need to send a message periodically. The `ping` method is provided for this purpose. +The gRPC server already sends pings to the client, so you can simply reply with a ping and your connection will remain open. +You can see in the rust example how to reply to the ping from the server with the client. + ### gRPC Tools #### Google Pub/Sub diff --git a/examples/rust/src/bin/client.rs b/examples/rust/src/bin/client.rs index 39cac8fb..46442d8a 100644 --- a/examples/rust/src/bin/client.rs +++ b/examples/rust/src/bin/client.rs @@ -524,7 +524,8 @@ async fn geyser_subscribe( request: SubscribeRequest, resub: usize, ) -> anyhow::Result<()> { - let (mut subscribe_tx, mut stream) = client.subscribe_with_request(Some(request)).await?; + let (mut subscribe_tx, mut stream) = + client.subscribe_with_request(Some(request.clone())).await?; info!("stream opened"); let mut counter = 0; @@ -549,6 +550,23 @@ async fn geyser_subscribe( ); continue; } + Some(UpdateOneof::Ping(_)) => { + // This is necessary to keep load balancers that expect client pings alive. If your load balancer doesn't + // require periodic client pings then this is unnecessary + subscribe_tx + .send(SubscribeRequest { + ping: Some(SubscribeRequestPing { id: 1 }), + slots: request.slots.clone(), + accounts: request.accounts.clone(), + transactions: request.transactions.clone(), + entry: request.entry.clone(), + blocks: request.blocks.clone(), + blocks_meta: request.blocks_meta.clone(), + commitment: request.commitment.clone(), + accounts_data_slice: request.accounts_data_slice.clone(), + }) + .await?; + } _ => {} } info!("new message: {msg:?}") From eb4fce5f88267ddaa71e7b3096a9827eace324b1 Mon Sep 17 00:00:00 2001 From: vovkman Date: Mon, 4 Dec 2023 18:33:08 -0800 Subject: [PATCH 2/2] update readme and rust example to show client ping --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 433ef5a5..cc770105 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ It's possible to add limits for filters in config. If `filters` field is omitted - [TypeScript](examples/typescript) **NOTE**: Some load balancers will terminate gRPC connections if there are no messages sent from the client for a period of time. -In order to mitigate this you need to send a message periodically. The `ping` method is provided for this purpose. +In order to mitigate this you need to send a message periodically. The `ping` field in the SubscribeRequest is used for this purpose. The gRPC server already sends pings to the client, so you can simply reply with a ping and your connection will remain open. You can see in the rust example how to reply to the ping from the server with the client.