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?