What is the best way to send actor updates to SSE?

My project is a set of nodes. Each node is an actor. A user can view a set of nodes (in a web page). Each node can have its state updated independent of user action.

(For instance, a user A might only be viewing nodes 2-4. Node 1 could receive a message from a different user. Node 1 would then propagate the message, through actor messages, resulting in state changes to nodes 3 and 4. User A should see those changes to 3 and 4.)

I want the user to see the accurate state of the node as it changes. Therefore, I want the server to transmit events to the client when these node state changes occur.

I was thinking I’d use Server Sent Events (SSE). When a user/client connects, it would indicate which set of nodes it is viewing. When the user/client changes which set of nodes it is viewing, it would communicate that to the backend; dropping some and adding others. The SSE connection would transmit state changes for all the nodes that the user/client is currently viewing.

I know how to set up the route thanks to https://doc.akka.io/docs/akka-http/10.0/sse-support.html .

I am wondering the best way to communicate the actor state changes to the route?

I am using akka cluster sharding and persistence on Akka 2.5 currently, but will update to 2.6 at some point. Each actor is identified by a uuid.

It sounds like I should use one EventBus across the entire cluster? And then any time an actor’s state changes, it would eventBus.publish(Msg(uuid, state)) ?

It sounds like EventStream is not an option since I am using Cluster. Is that also true for EventBus in general? Should I be looking to Distributed Pub/Sub or an external message queue/stream instead?

Finally, either way, is there an example of hooking that up to SSE in the akka-http route? Is this mostly a matter of creating some sort of listener actor for that “view” of nodes that the user cares about, and then somehow hooking that up to the Source that SSE needs?

Should I be looking to Distributed Pub/Sub or an external message queue/stream instead

Yes, if you want the events to be shared by consumers on every node. Note that Distributed Pub/Sub is at-most-once, so if you want guaranteed delivery the best way is to roll your own, or to use an external. Alpakka has a number of very easy drop-ins.

Finally, either way, is there an example of hooking that up to SSE in the akka-http route? Is this mostly a matter of creating some sort of listener actor for that “view” of nodes that the user cares about, and then somehow hooking that up to the Source that SSE needs?

Yup. With SSE I suspect you’d want to provide the “subscription” information in the Route via query parameters or request body, creating an actor to subscribe on behalf of that user’s connection, and instantiating an appropriate source that you can pipe messages to (Source.queue should work fine for this).