I'm trying to subscribe to the log stream of a remote akka ActorSystem, basically to write a console that shows the running logs of the remote Actors.
The only way I can think to do this is to: create an Actor within the logging ActorSystem, have that Actor subscribe to the ActorSystem.eventStream and then subscribe to that Actor using actorSelection from within my console's ActorSystem.
But this seems very "indirect" since the log pipeline would look like:
logging Actor --> eventStream --> Actor subscribed to eventStream --> local Actor
Is there an easier way to subscribe to the event stream?
From a simplicity viewpoint, nothing forbids you to subscribe a remote actor to your event stream without an additional actor. The Akka documentation mentions:
For illustration purposes, consider the following code fragment which corresponds to the remote system, the one you want to subscribe to:
And then the corresponding subscriber in the "local" node, from where you want to show the logs:
However, there are several caveats to this solution, as the fact that the publisher must be running before the subscriber (or the subscriber implement some retry policy until the publisher is up), the location is hardcoded and so on. If you want to have a more robust and resilient system and it's permissible, follow the advice in the documentation and use a distributed publisher-subscriber in a clustered environment which poses several advantages with a similar amount of boilerplate.
Hope it helped!