DEV Community

A beginners guide to gRPC with Rust

Anshul Goyal on April 24, 2020

Table of Contents Introduction Protocol Buffer Rust and gRPC Creating a Server Creating a Client Streaming in gRPC Authentication Concl...
Collapse
 
wotzhs profile image
Sean Wong

Hi Anshul, I am very new to Rust development, i find this article extremely helpful, however I am not quite clear with the statement below:

This will help us testing and maintaining code in save repo but it is not suggested for a large project

is this referring to the bin block in the cargo.toml? is so, may I know what would be the proper way to run the rust grpc server?

Collapse
 
anshulgoyal15 profile image
Anshul Goyal

Yes, the better way is to use cargo wrokspaces.

Collapse
 
wotzhs profile image
Sean Wong

Thanks Anshul, I have been looking at different gRPC crates and I think another way that to not use the cargo run --bin server is to use the statically generated code from protoc --rust_out and use them to build the grpc server manually.

Particularly I found github.com/tikv/grpc-rs.

I understood completely that this article was meant to demonstrate the dynamically genarated grpc server & client, so I hope this comment is not to be taken in the wrong light.

Thread Thread
 
anshulgoyal15 profile image
Anshul Goyal

Hi, Sean I always like to generate stubs at build time. It allows us to maintain a sync between protocol buffer definations and stubs. I think it is best practice to not to generate stubs before hand.

Thread Thread
 
wotzhs profile image
Sean Wong

yup, agreed, generating stub at build time guarantees the latest protobuf code, that's my preference too.

Collapse
 
marshalshi profile image
MarshalSHI

Hi Anshul,

Nice post. Thanks.

A question about CA. You used self-signed CA. and I did same like your posted. But my client cannot talk to server. It tells me transport error.

After checking online, I found that libwebpki said they are not supporting self-signed CA currently. (Link is here: github.com/briansmith/webpki/issue...)

Could you describe more for CA part? Thanks

Best,
Marshal

Collapse
 
vixorem profile image
Victor • Edited

HI! I'm having a trouble with streaming. I cloned your repo and ran server and cient. I tried function send_stream but modified it putting sleep(4 second) for each iteration in the spawned task. When I ran client I was expecting a short delay between messages I receive from the server but it worked differently. The delay took about 20 seconds without any incoming messages (4 iterations with 4 sleeps per eacn) and then I got all the messages at the moment. Why does it happen and how can I make streaming send and receive in time?

Collapse
 
vixorem profile image
Victor

I've set channel buffer size to 1 and it seems to be working but I don't undestand why

Collapse
 
dpineiden profile image
David Pineda

Hi!
Very thanks for your tutorial. Not so simple, not so complex. The just point.
Now I recommed to update the code for this days, changes a bit. I've shared my repo
gitlab.com/pineiden/gprc-tonic-rust
BR

Collapse
 
myleftfoot profile image
Stéphane Trottier

good sample, had to tweak the JWT sample code.

had to change

mut req: Request

to

mut req: tonic::Request

Collapse
 
akhilerm profile image
Akhil Mohan

Can you point to the complete code repository ?

Collapse
 
mikkelhjuul profile image
MikkelHJuul

He would have to add it, because it doesn't seem to be on his github.
for some small points, the name of the impl has to be Say (given by the .proto), the file hell.rs should probably have been hello.rs and is placed in folder src. This is my findings so far.
This should bring you to a state where if you have not added anything to your implementation the compiler will spit at you: not all trait items implemented, missing: ... which makes perfect sense

Collapse
 
anshulgoyal15 profile image
Anshul Goyal
Thread Thread
 
naveendavis11 profile image
Naveen Davis

I was using 2 bin. But
hello module is not getting imported to client.rs.

My src folder structure
client.rs
server.rs
hello.rs

Not sure whether I need to make lib.rs

Collapse
 
anshulgoyal15 profile image
Anshul Goyal

Hi
Sorry for the late reply.
Here is the code repo github.com/anshulrgoyal/rust-grpc-...

Collapse
 
akhilerm profile image
Akhil Mohan

Thank you.

Collapse
 
geoxion profile image
Dion Dokter

Very good post! This is exactly what I needed 😁

Collapse
 
shionryuu profile image
Shion Ryuu

title "Token-Based Authentication" is not correct show.

"use" is missing before "jsonwebtoken crate".