1.15.2 Event on Database Change?

Discussion in 'Spigot Plugin Development' started by JimiIT92, Jan 25, 2020.

  1. I'm using a SQL Database with my plugin where each User has a row associated. What I want to do is that when a value changes in the row the user gets notified. Since this happens outside of the plugin is there a way to detect those changes from the plugin? Or should I make a scheduled event that checks the row every so often?
     
  2. You should consider reading the thread I have linked in my signature below.
     
  3. RiotShielder

    Supporter

    What database are you using? What's causing the events?

    You could add a column to your table which tracks the last notification date. If the rows last updated date is > the last notified date then send a message to the player. Create an index to speed up the queries and have a thread which periodically queries the DB, notifies the player, and updates the last notified date.

    Otherwise if you can modify the code which is causing the updates you can send a message to a queue, insert a row in another table, or some other creative way to notify your plugin that something is to be done.
     
  4. Eh, not really the greatest solution. Obviously it works, and is probably the best solution if this is going to public plugin (as not many users will have access to a Redis server / other external software), besides adding multiple implementations.

    OP, if possible, use some kind of message queue, such as Redis pubsub or RabbitMQ to relay data between servers. You'll either want to relay the changes data directly, or just notify the other servers that there has been a change and that they should check the database
     
  5. I'm using a basic MySQL database which will run on the same machine as the server (since this would be just an authentication server). I've already thought about the running task that checks for modifications, but I'm wondering if there is a more elegant solution, and Rabbit seems to be it
     
  6. RiotShielder

    Supporter

    Rabbit (or any other messaging/queue based solution) is good, but it requires you to modify the application modifying the database which it seems like you do.
     
  7. Yep, since is a private plugin I'm in control of both the plugin's code and the database