本文介绍了SQL Server和消息队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个可靠的消息服务,或者至少这是我会怎样形容它

I'm trying to build a reliable message service, or at least that's how I would describe it.

下面是我的问题:我有一个表,我插入数据到这个表,我有从该表中选择的数据至少有两个应用程序。不过,我需要两个不同的应用从来没有选择在任何给定的时间相同的行的可靠方法。

Here's my problem: I have a table, I insert data into this table, I have at least two applications which select data from this table. However, I need a reliable way for the two different applications to never select the same rows at any given time.

我将如何去写一个交易或SELECT语句是保证不选择其他应用程序最近选择了相同的行。

How would I go about writing a transaction or select statement that is guaranteed to not select the same rows that other applications have recently selected.

我不是一个SQL Server的专家,但我希望类似这样的东西。

I'm not an SQL Server expert, but I would expect something similar to this.

从表中选择的工作,这会给应用程序中的某些行独占访问。然后,应用程序将处理这些行。某些行被删除,有些行返回到数据库中。

Select work from table, this will give the application exclusive access to some rows. The application would then process those rows. Some rows get deleted, some rows are returned to the database.

我主要担心的是,如果应用程序无法完成它的处理时,SQL Server将最终超时而归签出的数据,应用程序数据池。

My main concern is that if the application fails to complete it's processing, SQL Server would eventually time out and return the checked out data to the application data pool.

推荐答案

添加'正在处理'标志每条记录,这在设定。一个'原子'的方式

Add a 'Being Processed' Flag to each record, which is set in an 'atomic' way.

有过几个问题,很多答案在这里SO,相当类同这样的:

There have been several questions and many answers here on SO, quite similiar to this:

这篇关于SQL Server和消息队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:10