Answer the question
In order to leave comments, you need to log in
Is it possible to get information that a record has appeared in the database?
Petya sent a message to Vasya. How does Vasya know that he has received a message, should the server send requests after a certain time, or can the database itself notify that Vasya has a new record in the table? I can only suggest that the server can make queries to the database to check for new records and then send them to the client, but I don't think this is the right way. I did not work with the database, so far I only wrote / read from there. Thank you!
Answer the question
In order to leave comments, you need to log in
PostgreSQL has a notification mechanism . An example of usage in Go.
I did not work with the database, so far I only wrote / read from there.
Why not just send a notification via WebSocket after adding an entry to the database? It is not necessary to interrogate just like that in the database.
Pseudocode:
func onMessage(message Message) {
db.Save(message)
chat.Notification(message)
}
Firstly, there are triggers in the database.
Secondly, for high loads it is not done this way. Not through a DB, and through MQ.
depends on tasks, but it is worth looking towards RabbitMQ if you only need to forward messages
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question