Search code examples
scalamessageactorbus

Scala message bus implementation by Actors?


I want to implement some kind of message bus in one of my Scala applications. The features would be:

  • ability to subscribe to 1 .. N types of messages
  • messages may have payloads
  • loose coupling (nodes only hold a reference to the bus)
  • lightweight (no fully blown enterprise message queue etc.)

What I plan to do is to implement all nodes and the bus itself as standard Scala actors. For example I want to define a trait Subscriber like this:

trait Subscriber[M <: Message[_]] {
  this: Actor =>
  def notify(message: M)
}

Ideally mixing in this trait should already register the subscription for the type M.

So does this idea make sense? Are there better approaches to realize a message bus?


Solution

  • Disclaimer: I am the PO of Akka

    Hi Itti,

    This has already been done for you in Akka, the Actor Kernel: www.akka.io

    Docs: http://doc.akkasource.org/routing-scala

    Pub/Sub: Akka Listeners Routers: Akka Routers Convenience: Akka Routing