Problem
I have a SQL table of message records, tbl_message_queue
, that each have a release timestamp field (now or in the future). New records are constantly being inserted.
When release timestamp(s) come of age, the eligible records need to be processed by a console app .exe. Upon process completion, respective records will be removed from tbl_message_queue
.
Lag time between release timestamp an execution should be reduced/eliminated.
Option #1: Frequent polling
I could set my .exe to run every 10-15 seconds via Windows Task Scheduler. Which would include a SQL statement like:
SELECT *
FROM tbl_message_queue
WHERE qmsg_ts_release <= GETDATE()
This feels like an inefficient, brute force, lag-friendly solution. But it's a structure I'm most familiar with.
Option #2: Re-scheduled SQL agent job
I've never tried this, but seems like it could work. It sounds really hack-y, so please forgive me if this is a really bad idea.
I could create a SQL agent job that has a CmdExec Job Step, and continually reschedule the job on:
UPDATE qmsg_ts_release
INSERT tbl_message_queue
- Completion of .exe
to run next at MIN(qmsg_ts_release)
.
Phew... I know that sounds really ugly, but it's not aggressively polling, and would probably eliminate any lag.
Other options
Are there any other options or better solutions for this type of problem? I'm not familiar with best-practices in message queue architectures.
Would something like MSMQ or SQL Server Service Broker work better for this type of problem? I have very little familiarity with other options and am not sure where to start.