How to create a real-time notification system?

I have a requirement when I have to send warnings when a record in db is not updated / changed for certain intervals. For example, if the received purchase order is not processed within one hour, a reminder should be sent to the delivery manager.

A reminder / warning should be sent exactly at the interval (including seconds). If the last modified time is 13:55:45, then the warning should be activated at 14:55:45. You can track millions of lines.

A simple approach could be to implement a custom scheduler, and all records will be registered with it. But you should poll the database to look for changes every second, and this will lead to performance problems.

UPDATE:

Another basic approach would be to create a thread for each record and put it into sleep mode for 1 hour (or) Using some concept of queues that has a timeout. But still he has performance problems.

Any thoughts on a better approach to implementing the same?

+4
source share
4 answers

probably using an internal JMS queue would be a better solution - for example, you can use the scheduled message function http://docs.jboss.org/hornetq/2.2.2.Final/user-manual/en/html/examples.html#examples .scheduled-message using hornetq.

You can ask the broker to publish a warning message after exactly 1 hour. On the other hand, during the processing of some trading activity, you can manually delete this message, which means that the trading activity was processed without errors.

+2
source

Use a timer for each .ie reminder. If the last changed time is 17:49:45, then the warning should be triggered 18:49:45, you just have to create a dynamic timer planning for each task, which it will call accurate after one hour.

+2
source

This is not possible in Java if you really insist on "real time." In Java, you can take the garbage collection phase in the world, and you cannot guarantee the exact time.

If the approximate time is also valid than using any scheduled queue as suggested in other answers, if not than using real-time Java or some kind of native call.

+2
source

If we can assume that orders are being introduced with increasing time, then:

You can use Queue with elements that have the time-of-order and order-id properties.

Each new record added to the database is also placed in the Queue .

You can check the item at the beginning of Queue every minute.

When checking an element at the beginning of Queue , if an hour has passed from time-of-order , then search for the record with order-id in the database.

If it is found and has not been updated, send a notification, otherwise remove it from Queue .

0
source

All Articles