电子邮件监控同步
我正在编写一个 C# 程序,该程序使用 POP3 来监视专用 Gmail 帐户的专门命令电子邮件并做出适当的反应。
为了获得最大的可靠性,我将在全国各地的多台计算机上运行该程序。 我目前有一个竞争条件,程序的两个实例可以在其中一个实例删除同一条消息之前读取该消息,从而导致该消息被处理两次。
如何确保每个命令只处理一次?
Gmail 的 POP3 访问过去只为每封邮件提供一次(使 RETR 和 DELE 成为单个原子操作),但我无法再重现此行为。
计算机之间通信的唯一方法是 SQL Server 和 HTTP 服务器(由我控制)。
I'm writing a C# program that monitors a dedicated Gmail account using POP3 for specialized command emails and reacts appropriately.
For maximum reliability, I will run this program on several computers throughout the country.
I currently have a race condition where two instances of the program can read the same message before one of them deletes it, causing the message to be processed twice.
How can I make sure that each command is processed exactly once?
Gmail's POP3 access used to only serve each message once (making RETR and DELE a single atomic operation), but I can no longer reproduce this behavior.
The only method of communication between the computers is a SQL Server and an HTTP server (which I control).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想到的一个选择是使用 POP3 的 UIDL 命令,并在 SQL Server 中创建一个表,其中包含已处理的 UIDL 的唯一列。
然后,在下载每条消息之前,守护进程会将 UIDL 插入表中,如果出现错误,则跳过该消息。 (我假设 SQL Server 的 INSERT 命令是原子操作)。
One option I've thought of is to use POP3's UIDL command, and have a table in SQL Server with a unique column of UIDLs that were already processed.
Then, before downloading each message, the daemon would INSERT the UIDL into the table, and, if it got an error, skip the message. (I'm assuming that SQL Server's INSERT command is an atomic operation).
首先我必须承认我不知道 POP3 支持哪些命令,但是...如果您可以执行显式“DELE”并在消息不再存在时收到错误,那么我会说:
编辑:
阅读 RFC1939 后,这种方法应该有效; 来自 RFC:
这当然是假设 Gmail 实现实际上遵循 RFC。
First I must admit I do not know what commands POP3 supports, but... if you can do an explicit 'DELE' and get an error if the message no longer exists, then I'd say:
EDIT:
After reading RFC1939, this approach should work; from the RFC:
This is ofcourse assuming that the Gmail implementation actually honours the RFC.