i want to make a messenger with websockets, and rabbitmq.
when someone sends a message, the message is sent from the front end to the spring server via a websocket connection. Then once the message is in spring, i want it to be sent to rabbitmq which then will be sent back into spring but to the database controller classes.
Is this right?
And if so then where do i go from here? Do i send a signal back to the front end via websockets that it needs to refresh and re-query the database for the messages, after each database insert?
#if i make a messenger with websocket, when should i query the messages from the database?
1 messages · Page 1 of 1 (latest)
<@&987246841693360200> please have a look, thanks.
am i on the right path with this plan?
Depends entirely on your use case. In many cases, calls like this are perfectly fine as a synchronous endpoint, but I guess thats not the question.
It going to spring and then into the rabbitMQ queue is perfectly fine - I think there are ways in moden cloud infra to offer an endpoint that allows the FE to directly insert into the queue, but that's usually not really good as it's decoupled from your usual auth logic.
Reading it then to do anything is also fine.
The usual issue with these systems, as you figured out, is how to bring the feedback to the user. This is entirely up to the design, i.e. Jira has small notification popups when you clone an issue, that show the link to it and a simple message. In other cases, you can have it return a specific message that triggers a GET from the FE.
I.e. for one use case at my work, we decided to go the easy route and just have periodic refreshes of the data, issue being that there are always n >= 1 working on the same data
I think the purpose/functionality you want to achieve here is: Im a frontend sender and once my outgoing msg is secured into the DB, I should show the user that your msg is "sent". Am I right?
Or you just want to refresh and query because you want to fetch the whole msg list from DB, whenever there's a DB change
This sounds like a lot DB queries, but its a simple design to implement.
You can insert directly to RabbitMQ from the front end but not purely with React, it requires you to setup a NextJS or some other JS backend, and i decided not to.
Yes, i think the simplest (or at least the way im most comfortable) is to send back a websocket message back to the front end which triggers a database fetch.
Thank you for confirming that im going the right way, i appreciate it.
Yes, i was initialy planning to just query the last maybe 15 messages in the room ... but clearly there are some issues with this
well yesnt. You could also do a simple lambda call for it if youre on AWS for example. Azure also has something specific for this (or had, dont quite know if they still offer it)
For specific things, which are limited in data size, we also push the updated data via websocket to the FE
if i want to let the user create a new chatting room, i need to first make a call to the backend controller to insert the room into the database, then in that same controller after the insertion is done, using the id of the new room i create a new rabbitMQ exchange called room(id) ? What do i do with the queues, they are meant to represent each user, how do i let rabbitMQ know which user to send to?
Generally the client listens to the rooms it's interested in. So if the user can create one, he should, upon the POST, receive the identifier for it so he can start listening already whilst the backend finalizes the rest.
we use socket.io for the websocket part
rabbitMQ in your above example doesn't send anything to the user, so why would it?
Is the websocket and rabbit's use to learn them?
I think you might want to add a cache Layer to reduce DB load, like Redis
Yes, and also i plan to look for work with this project also
Thanks! I will
Is this something i should consider adding after i finish my design or is it something i will have to design my program around?