Long live grpc stream in bidirectional streaming
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
We've discovered a problem using tonic lib for our rust client, trying to send streaming messages, seems like tonic recreate the stream on every message, so more featured server which logic is concreted to listen same stream(for perfomance, resources issues, etc), receiving complete stream signals and new one being created
`
fn send() {
let data = SomeData {
...data
};
let response = match self.client.put_data(tokio_stream::iter(vec![data])).await {
Ok(res) => res,
Err(st) => ...fail processing,
};
}
`
i am suspicious that put_data(tokio_stream::iter(vec![data]) is recreating stream on each send() function call
example in repo have the same behavior https://github.com/hyperium/tonic/blob/master/examples/src/streaming/client.rs#L35
is there anyway to avoid such behavior? maybe different approach with example?
i saw the way with channels like so
`
let (tx, rx) = mpsc::unbounded_channel();
let stream = UnboundedReceiverStream::::new(rx);
`
and then pass the stream directly to client.put_data like so
`
let response = match self.client.put_data(self.stream)
`
but here's the same problem, stream will be recreated each time and if i want to store that stream in the struct i cannot move it then later, so i cannot just spawn task with infinite loop, cause i need to process data from response streams, is there any way to solve this issue?
what i want basically something like https://grpc.io/docs/languages/go/basics/#client-side-streaming-rpc-1
where i can initiate stream like so stream, err := client.RecordRoute(context.Background())
and then use it across entire app
if err := stream.Send(point); err != nil {
log.Fatalf("%v.Send(%v) = %v", stream, point, err)
}
Contributor guide
Assessment
This issue has not been assessed yet.