Using SQL Server as a DB queue with multiple clients

前端 未结 7 1003
生来不讨喜
生来不讨喜 2020-12-04 08:06

Given a table that is acting as a queue, how can I best configure the table/queries so that multiple clients process from the queue concurrently?

For example, the ta

7条回答
  •  囚心锁ツ
    2020-12-04 08:50

    Rather than using a boolean value for Processed you could use an int to define the state of the command:

    1 = not processed
    2 = in progress
    3 = complete
    

    Each worker would then get the next row with Processed = 1, update Processed to 2 then begin work. When work in complete Processed is updated to 3. This approach would also allow for extension of other Processed outcomes, for example rather than just defining that a worker is complet you may add new statuses for 'Completed Succesfully' and 'Completed with Errors'

提交回复
热议问题