marcoferrer / kroto-plus

gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example of server stream subscription

AliceCarroll239 opened this issue · comments

Hello

Can you provide an example of how to subscribe to a server stream please?
In my case, the server sends messages to the stream every second, but when I connect to it like:
Screenshot at Oct 17 17-13-11

I get messages every 1-2 minutes.

That’s a bit odd. I can’t immediately tell what your issue might be. Do you have snippet or example of what your server side imple looks like for this endpoint?

In the example project there is a sample of a ticker service. This might help some but if you’re still having issues I’m happy to help. A key thing to note is that this example binds a single producer broadcasting to multiple clients. Which might be the same as your use case.

https://github.com/marcoferrer/kroto-plus/blob/master/example-project/src/main/kotlin/krotoplus/example/MultipleClientSubscriptionsExample.kt

For a one to one service to client impl something like this might be what you're looking for.

    override suspend fun listen(request: Empty, responseChannel: SendChannel<Tick>) {
        while(isActive){
             responseChannel.send(...)
             delay(1000)
        }
    }

I can give the following example

In the golang, I just wrap the method in a FOR loop and get the following (this is what I need)
GoExample
In kotlin I get the following output (and I don’t get into the loop, the output comes from the consumeEach method once every 1 minute)
KotlinExample

My question is how your library implement similar behavior
Maintain a connection to the stream and get values ​​from it constantly

So my current best guess is that in someway the behavior of the flow control implemented in grpc go differs from the java impl. If thats the case, this would be an interop bug that should be fixed in kroto. Ill need to get a sample project together to reproduce the issue, but after that I should be able to track down the source of the problem. Thanks again for reporting this!