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

chore(client): Update readme and rust example #2

Merged
merged 2 commits into from
Dec 5, 2023
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 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.

### gRPC Tools

#### Google Pub/Sub
Expand Down
20 changes: 19 additions & 1 deletion examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:?}")
Expand Down
Loading