How do I receive a notification whenever there is a new record in a database table?

10

I need to receive a notification whenever there is a new record in a particular database table, what can I do to receive?

  • If I make an Ajax request every time, I'll make unnecessary requests.

  • Any other ideas?

  • asked by anonymous 04.01.2014 / 18:10

    1 answer

    5

    Define an architecture

    If you want something portable between banks you should do it on your system. Create a design pattern like: VIEW --- > Service ---- > DAO (or Repository).

    DAO would be responsible for whether or not a particular record was updated, either by caching that could be used with Ajax or by WebSocket where a notification would be sent.

    Displaying in View: WebSocket

    You could use HTML5 + WebSocket to send the values to the screen. Every time a record is updated in DAO (or Repository), a notification would be sent to the view.

    The WebSocket approach works with the server sending the notification to the page, the reverse of an ajax notification where the page fetches the value.

    Displaying in View: Ajax

    When using Ajax you do not have to go to the database all the time to see if there is a change.

    You could have this value cached in memory, if there were any changes, the new value would be returned. If there was no change, you did not return anything. It would be something like, you would send the date of the last query: 10/10/10 10h10min. If the cache value were the same, you do not have to go to the bank. If the cache value indicates that the newest registration time was 10/10/10 10h15min there you would look for the new information.

    An Ajax call would not cause this overload on the server since we would be messing around with a cached value.

    Conclusion

    Each approach has its advantage and disadvantage. Just choose the one that best fits your project profile.

    Attention: If the value in question is constantly updated, regardless of approach, there will be a lot of data traffic on the network.

        
    04.01.2014 / 22:25