I have two applications. One use the node.js, the second use php.
I'm looking for a way to listen changes to a notifications
table that a node.js makes.
Here's the pseudocode:
$database->whenInsertToTable('notifications', function() {
// Do something with new notifications...
});
At the moment, the only implementation option I see is creating a task that will, for example, check the notification table every minute, but there is a drawback. If the insert was made immediately after the last check, then we will get a 59 second delay.
It seems to me that checking the table every second is also not the best solution, because this is a select every second. I'm trying to find a ready-made solution/library that would listen to database events.
CodePudding user response:
One possible approach would be to use a message broker like RabbitMQ. node.js would insert into the database and then publish an event on Rabbit. PHP will listen to this event and trigger whatever logic you want to attach this event.
Or you could call an API in you PHP application from node.js after the insert. This would probably be more lightweight if this is only for a smaller application.