Hi everyone! I'm looking to implement a long-livin...
# grpc
a
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
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
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
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