ACME's Message Dispatcher
ACME's Message Dispatcher
The ACME Corporation develops an ample range of commercial software, from desktop
applications, mobile apps, web applications to microservices.
The company's engineering teams use Java or other JVM languages. Multiple teams face a
similar problem: they have internal objects that generate multiple messages and other objects
interested in receiving them. They don’t know how to efficiently dispatch the messages from the
producers to the correct consumers.
You are a top skilled software engineer in ACME company and were selected to tackle that
issue. Your objective is to create a library in Java or other JVM language like Kotlin or Scala for
the other team developers to use in their projects.
Because of the myriad of different applications, your library should not use external
dependencies, only components already provided in your language’s standard library. It should
handle exclusively the matter of receiving a bunch of messages (multiple times and constantly),
and dispatching them to the correct consumers.
If you are more comfortable with non-JVM languages, feel free to prepare for this exercise in
some node.js or Go or Rust or your other favorite language. Be prepared to explain the code to
the interviewer who may not speak the language as well as you do!
Just keep in mind that the objective is to implement a library, not a full-fetched application. In
other words, don’t worry about HTTP / gRPC / etc. endpoints, RESTful decorators, database
interactions, etc.
● A Message class
Example:
When processing one message with topics: ["Red", "Ball"], the message
dispatcher will dispatch the message to:
- consumer C1 because it is registered to a topic linked to the "Ball" topic.
- consumer C2 because it is registered to the topic "Ball".
- consumer C4 because it is registered to all messages.
- consumer C5 because it is registered to the topic "Red" and it is
registered to a topic linked to the "Ball" topic