#if i make a messenger with websocket, when should i query the messages from the database?

1 messages · Page 1 of 1 (latest)

sinful agate
#

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?

wind canopyBOT
#

<@&987246841693360200> please have a look, thanks.

sinful agate
#

am i on the right path with this plan?

solemn night
#

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

teal jungle
#

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

teal jungle
sinful agate
sinful agate
solemn night
solemn night
sinful agate
#

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?

solemn night
#

rabbitMQ in your above example doesn't send anything to the user, so why would it?

oak axle
teal jungle
#

I think you might want to add a cache Layer to reduce DB load, like Redis

sinful agate
sinful agate
tropic pebble
#

It's something to keep in mind, but don't preemptively add something before you're sure you'll need it.

#

And you can always add in memory cache.

solemn night
#

altho it doesnt make much sense to cache here, if the request itself manipulates data that then needs to be sent out

#

what you can do is send out the updated data via websocket in the same "run" as the modification was done