dimsuz
08/11/2021, 5:47 PMwire
+ grpc
question. If I have a service like this
rpc getItemsStream(ItemRequest) returns (stream ItemResponse) {}
How do I send the initial request? Wire generates the implementation of GrpcStreamingCall which has 2 channels.
Do I understand correctly that I must send initial request using a sendChannel
?
My issue posted above seems to be caused by no request body being sent. Sending it to the channel doesn't help, maybe I must do it otherwise?
Stub implementation generated by grpc-kotlin
library has this explicitly: fun getItemsStream(request: ItemsRequest): Flow<Response>
, but wire
generates function with no params in this case.dimsuz
08/11/2021, 6:07 PMsendChannel.send(ItemsRequest())
sendChannel.close()
And now things went alive! I can see in server logs that events are being sent from server to client.
If this is the right way to do this, you really should document this, wasted a lot of time of this "obvious" stuff 🙂dimsuz
08/11/2021, 6:08 PMokhttp.OkHttpClient I [53 ms] responseBodyStart
and then silence.
Am I again not consuming them right? I call receiveChannel.receive()
on the client.Benoit Quenaudon
08/11/2021, 6:52 PMsendChannel
it closes the whole connection.
You wanna send request on one thread, and read the responses on another.
If you close any of them, the connection dies.dimsuz
08/11/2021, 7:36 PMGlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
val (send, receive) = service.someStreamingCall().execute()
send.send(MyRequest())
for (resp in receive) { println(resp) }
}
...then I'm effectively blocking a thread? Because I do it like above and
a) either send doesn't work, no request body goes out, times out
b) adding 'close()' after send actually causes server to receive the request, but then connection is closed
This would explain things, but then... if I remove this for
it still doesn't send the body. Eeeh. I hope I'll figure this out, wire
is soooo much simpler than "native" grpc stuff.jessewilson
08/11/2021, 10:27 PMjessewilson
08/11/2021, 10:27 PMBenoit Quenaudon
08/11/2021, 10:29 PMdimsuz
08/11/2021, 11:05 PMclose()
I can see that server keeps sending me outbound data requests in the stream. But for some reason I dont receive them in the receive channel, okhttp's event listener reports readResponseBody
and nothing after that, I guess no body is being read.
wire's sample has only bi-directional streaming example, so I'm not sure if i'm doing everything right, but I do it like in the snippet I posted above.dimsuz
08/12/2021, 1:08 AMclose()
, while connection is not closed, but logging interceptor prints <--- 200 OK
, so does this mean that the streaming response is considered to be done/finished? Maybe that's why I don't receive anything in the receive channel? (streaming responses still continue to 'tick' in the server logs)Benoit Quenaudon
08/12/2021, 8:11 PMBenoit Quenaudon
08/12/2021, 8:18 PMdimsuz
08/12/2021, 9:28 PMBenoit Quenaudon
08/12/2021, 9:38 PMBenoit Quenaudon
08/12/2021, 9:38 PMdimsuz
08/12/2021, 10:00 PMBenoit Quenaudon
08/12/2021, 10:57 PMdimsuz
08/12/2021, 11:41 PMRob Smith
08/13/2021, 1:16 AMRob Smith
08/13/2021, 1:18 AMreceiveOrNull
which is error deprecated for receiveCatching().getOrNull()
. Maybe I'm missing something?Rob Smith
08/13/2021, 1:21 AMreceiveCatching
in my loop to get data, I don't have to close()
the sendChannel in order to receive that one message. But if I try to use the for (update in receiveUpdateChannel)
stuff, it only receives that one message if I do close
the channel.dimsuz
08/13/2021, 10:58 AM