Search code examples
scalarabbitmqamqpapache-kafkamessage-bus

Using message bus as replacement for regular message passing between actors (e.g., in scala)


I have a Java web-service that I am going to reimplement from scratch in Scala. I have an actor-based design for the new code, with around 10-20 actors. One of the use-cases has a flow like this:

Actor A gets a message a, creates tens of b messages to be handled by Actor B (possibly multiple instances, for load balancing), producing multiple c messages for Actor C, and so on.

In the scenario above, one message a could lead to a few thousand messages being sent back and forth, but I don't expect more than a handful of a messages a day (yes, it is not a busy service at the moment).

I have the following requirements:

  1. Messages should not be lost or repeated. I mean if the system is restarted in the middle of processing b messages, the unprocessed ones should be picked up after restart. On the other hand, the processed ones should not be taken again (these messages will in the end start some big computation, and repeating them is costly).
  2. It should be easily extensible. I mean in the future, I may want to add some other components to the system that can read all the communication (or parts of it) and for example make a log of what has happened, or count how many b messages were processed, or do something new with the b messages (next to what is already happening), etc. Note that these "components" could be independent applications written in other languages.

I am new to message bus technologies, but from what I have read, these requirements sound to me like what "message buses" offer, like RabbitMQ, Kafka, Kestrel, but I also see that akka also offers some means for persistence. My problem is, given the huge range of possibilities, I am lost which technology to use. I read that something like Kafka is probably an overkill for my application. But I am also not sure if akka persistence answers my two requirements (especially the extensibility).

My question is: Should I go for an enterprise message bus? Something like Kafka? Or something like akka persistence will do? Or would it be just faster and more appropriate if I implement something myself (with support for, say, AMQP to allow extensibility)?

Of course, specific technology suggestions are also welcome if you know of something that fits this purpose.


Solution

  • A Message Bus (typically called Message Brokers) like RabbitMQ can handle "out of the box" all of the messaging mechanisms you describe in your question. Specifically:

    RabbitMQ has the ability "Out of the Box":

    • To deliver messages without repeating the message.
    • To extend the system and add logging and have statistics like you describe.