I am new to the Elixir ecosystem. We are building system composed of the following layers:
- A database layer,
- A middleware layer containing our business logic and being written in a statically typed OOP language for a variety or reasons. This middleware exposes an internal HTTP API that can only be consumed by the web layer.
- A web layer that we are strongly weighting writing in Phoenix and LiveView. The web layer can be accessed by external consumers
Since Phoenix would not have direct access to the database, I am wondering how we could leverage the real-time update capabilities of LiveView to do things such as notifying individual users when they receive a new message, or when a new article has been added to a feed to which they are subscribed.
Since my understanding is that there is dedicated a LiveView process per user, I am wondering if it would be sound create one RabbitMQ queue per user. Then after a user has logged in, a queue consumer would be registered in the LiveView process of each individual user. The consumer would then be discarded when the user leaves the website.
RabbitMQ makes it easy to have messages discarded if no one is listening to a queue, so i’m thinking this could be a great fit for LiveView. Could you please tell me if you think this approach fits the intended use of Phoenix/LiveView, and if so could you please provide me some pointers on how I’d go about implementing it in Phoenix (namely, what would be the best RabbitMQ client library to use, and where would I need to hook in LiveView).