Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Akka EventBus work with remote actors?

Tags:

akka

Does Akka's EventBus work with remote actors?

As far as I can tell, it doesn't natively support this. Can anyone confirm please?

It looks like it would be possible to code some Actors that provide similar functionality. E.g. start up a remote actor that subscribes to the EventBus on the remote server, and send the messages back to a local actor to republish on the local EventBus. But there is no point writing this, if it is already supported!

Thanks

like image 796
Rob Wilton Avatar asked Nov 21 '12 15:11

Rob Wilton


People also ask

How do actors communicate in Akka?

Actors communicate using asynchronous messages. This ensures that the sender does not stick around waiting for their message to be processed by the recipient. Instead, the sender puts the message in the recipient's mailbox and is free to do other work.

How does Akka remoting work?

Akka has two ways of using remoting: Lookup : used to look up an actor on a remote node with actorSelection(path) Creation : used to create an actor on a remote node with actorOf(Props(...), actorName)

What is EventBus?

EventBus is an open-source library for Android and Java using the publisher/subscriber pattern for loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.

Are Akka actors threads?

Akka actors use java threads internally. More than a few thousand threads running simultaneously produces overhead on most desktop machines. Akka Actors simplifies this problem by providing awake-on-demand actors who do not occupy a thread unless they have some work to do.


1 Answers

The EventBus itself is local, meaning that events are not automatically transferred to EventBuses on other systems, but you can subscribe any ActorRef you want, including remote ones. You only need an actor on the node where the events are generated:

case class Subscribe(clazz: Class[_])
system.actorOf(Props(new Actor {
  def receive = {
    case Subscribe(c) =>
      context.system.eventStream.subscribe(sender, c)
  }
}), "eventer")

Then you can look that one up from remote hosts and have yourself subscribed.

like image 102
Roland Kuhn Avatar answered Nov 17 '22 01:11

Roland Kuhn