You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After significant amount of investigation on [how to send FileBox name with stream message], I finally figured out the solution, which does not require any extra info in the request or response messages.
Example
Server
messageFileStream: async(call)=>{// Get some arguments from the requestconstid=call.request.getId()// Get the stream from FileBoxconstfileBox=FileBox.fromFile(`${__dirname}/test.json`)conststream=awaitfileBox.toStream()// Create a shared response to use in streamconstresponse=newMessageFileStreamResponse()response.setName(fileBox.name)// Create a metadata to store the extra info and send it to clientconstmetaData=newgrpc.Metadata()metaData.add('fileName',fileBox.name)call.sendMetadata(metaData)stream.on('data',(data: Buffer)=>{response.setData(data)call.write(response)}).on('end',()=>{call.end()})},
Client
publicasyncmakeCallStream(i: number){// construct a request with parametersconstrequest=newMessageFileStreamRequest()request.setId(i.toString())// make the call to the server and get the stream responseconststream=this.grpcClient.messageFileStream(request)// read the metadata and get the extra info from itconstfileName=awaitnewPromise<string>((resolve,reject)=>{stream.once('metadata',(metaData: grpc.Metadata)=>{constnameValues=metaData.get(FILE_BOX_NAME_METADATA_KEY)resolve(nameValues[0].toString())})})constoutputStream=newPassThrough()// read data from the streamstream.on('data',(response: MessageFileStreamResponse)=>{oStream.write(response.getData())}).on('end',()=>{oStream.end()})constfileBox=FileBox.fromStream(outputStream,fileName)returnfileBox}
So with this design, we don't need extra attributes that we added onto MessageImageStreamResponse, MessageFileStreamResponse and MessageSendFileStreamRequest , to make the proto clear, let's remove these attributes.
The text was updated successfully, but these errors were encountered:
I just realized that when we want to send FileBox via grpc, the message should always be the same, so let's use a common message definition for the message that is actually a FileBox.
After significant amount of investigation on [how to send FileBox name with stream message], I finally figured out the solution, which does not require any extra info in the request or response messages.
Example
Server
Client
So with this design, we don't need extra attributes that we added onto
MessageImageStreamResponse
,MessageFileStreamResponse
andMessageSendFileStreamRequest
, to make the proto clear, let's remove these attributes.The text was updated successfully, but these errors were encountered: