Sending streams to a server (gRPC, Tonic)

Is there a stream type that can be used to send data from the client to the server?

I have a simple gRPC service built on the Tonic library. And I want the server to forward an incoming stream to another server. The issue is that I can't find a stream type compatible with the wrapper: tonic::IntoStreamingRequest.

Streams sent by server to a client are only required to satisfy the type tonic::codec::Streaming. For this, I used a Tokio channel wrapped in tokio_stream::UnboundedReceiverStream.

However, streams sent by the server to the client need to implement tonic::IntoStreamingRequest. The docs say that arguments should be automatically wrapped to satisfy the trait. What types can be wrapped? Does it only accept iterators?

Never used tonic before but in the docs, it looks like there is a blanket implementation for IntoStreamingRequest for T: Stream + Send + Sync + 'static

impl<T> IntoStreamingRequest for T
where
    T: Stream + Send + Sync + 'static,
1 Like

Ah right, thank you. So I can use tokio streams since they implement all of those requirements. What had me stuck was that a tokio_stream wrapper is also needed.
Here is what that looks like for anyone interested.

let (sender, receiver) = tokio::sync::mpsc::unbounded_channel::<CreateFileRequest>();
let receiver_stream = tokio_stream::wrappers::UnboundedReceiverStream::new(receiver);

let mut client = FileStoreClient::connect(host_port).await.unwrap();
client.create_file(receiver_stream);

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.