N
N
Nube2018-01-30 15:27:12
PostgreSQL
Nube, 2018-01-30 15:27:12

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

5 answer(s)
S
Sergey Gornostaev, 2018-01-30
@Nube

PostgreSQL has a notification mechanism . An example of usage in Go.

A
Alexey, 2018-01-30
@AlexMaxTM

I did not work with the database, so far I only wrote / read from there.

That's when you write a new message there, then process it as an event.

V
Vladislav, 2018-01-30
@ghostiam

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)
}

I
InoMono, 2018-01-30
@InoMono

Firstly, there are triggers in the database.
Secondly, for high loads it is not done this way. Not through a DB, and through MQ.

L
Leonid Nikolaev, 2018-01-30
@nikonor

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 question

Ask a Question

731 491 924 answers to any question