https://kotlinlang.org logo
#grpc
Title
# grpc
a

Andrés Romero

01/25/2023, 6:41 PM
Hi everyone! I'm looking to implement a long-living server stream with gRPC that clients can subscribe to. Context: there is a group of users with users and a lead user, when the lead starts and action
performAction()
which is a unary RPC. I want to notify the other users with information about that action. I would expect those members to be subscribed to another long-living RPC that facilitates sending that information. Do you have any examples of how can achieve that in Kotlin? I was looking into something like: https://dev.bitolog.com/grpc-long-lived-streaming/ https://sultanov.dev/blog/grpc-long-lived-streaming-using-observer-pattern/ But those implementations are written in Go and Java, and I'm struggling to find examples in Kotlin
🆘 1
m

Minsoo Cheong

01/26/2023, 2:49 AM
use a server side streaming rpc. grpc-kotlin creates a method for such rpcs that returns a Flow object. just return a flow that emits the action information. You would need an external event broker (maybe redis PUBSUB? your choice) to subscribe from. Then, when performAction() is called, broadcast the event to the broker.
a

Andrés Romero

01/26/2023, 3:05 AM
That’s the part that is hard for me to understand, how can I broadcast that event to the clients listening to that server side streaming rpc from another rpc / part of my application?
m

Minsoo Cheong

03/29/2023, 8:33 AM
I missed your question 😓 you could have clients flows that relay a single sharedflow and emit value to the sharedflow when event occurs to broadcast to multiple clients
71 Views