Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 309
Andreas Eisele Avatar asked Oct 19 '25 01:10

Andreas Eisele


1 Answers

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

like image 73
Viktor Klang Avatar answered Oct 21 '25 14:10

Viktor Klang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!