我正在编写一个C#程序,它使用POP3监控一个专用的Gmail帐户,以获取专门的命令电子邮件,并做出适当的反应。
为了获得最大的可靠性,我将在全国各地的几台计算机上运行此程序。我目前有一个竞争条件,程序的两个实例在其中一个实例删除消息之前可以读取相同的消息,从而导致消息被处理两次。
如何确保每个命令都被恰好处理一次?
Gmail的POP3访问过去只为每条消息提供一次服务(使RETR和DELE成为单一的原子操作),但我不能再复制这种行为。
计算机之间通信的唯一方法是SQL Server和HTTP服务器(由我控制)。
发布于 2009-05-27 00:57:29
我想到的一个选择是使用POP3的UIDL命令,并在SQL Server中创建一个表,其中包含已处理的唯一一列UIDL。
然后,在下载每条消息之前,守护进程会将UIDL插入到表中,如果出现错误,则跳过该消息。(我假设SQL Server的INSERT命令是原子操作)。
发布于 2009-05-27 01:21:14
首先我必须承认我不知道POP3支持什么命令,但是...如果您可以显式地执行'DELE‘,并在消息不再存在时得到一个错误,那么我会说:
仅当message
编辑:
在阅读了RFC1939之后,这种方法应该是有效的;
DELE msg
Arguments:
a message-number (required) which may NOT refer to a
message marked as deleted
Restrictions:
may only be given in the TRANSACTION state
Discussion:
The POP3 server marks the message as deleted. Any future
reference to the message-number associated with the message
in a POP3 command generates an error. The POP3 server does
not actually delete the message until the POP3 session
enters the UPDATE state.
Possible Responses:
+OK message deleted
-ERR no such message
Examples:
C: DELE 1
S: +OK message 1 deleted
...
C: DELE 2
S: -ERR message 2 already deleted当然,这是假设Gmail实现实际上支持RFC。
https://stackoverflow.com/questions/913487
复制相似问题