4

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?

Andreas Eisele
  • 743
  • 1
  • 9
  • 19

1 Answers1

5

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

Viktor Klang
  • 26,479
  • 7
  • 51
  • 68
  • I take your answer as a "yes you can realize a bus-like system by usage of actors". I will probably do my own implementation but will invest some time looking into what Akka can provide. Thank you! – Andreas Eisele Dec 10 '10 at 20:04