Pop3多进程,一次处理一条消息

发布于 2024-10-04 06:47:13 字数 204 浏览 0 评论 0原文

我正在使用 .NET POP3、.net 3.5 和 2008。

我在多台计算机上安装了 Windows 服务。每台机器(机器中安装的windows服务)访问相同的收件箱POP3(相同的帐户)来处理邮件。

使用多线程,多个脚本同时运行其实是比较理想的,是否可以使用POP3组件?

对于任何机器,每条消息必须处理一次(只有一台机器必须处理该消息)。

I'm using .NET POP3, .net 3.5, vs 2008.

I have a windows service installed in several machines. Each machine (windows service installed in machine) access to the same inbox POP3 (the same account) for process messages.

Using multi-threading, multiple scripts running at the same time is actually ideal, is it possible using the component POP3 ??

Each message must be process once time, for any machine (only one machine must process the message).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坏尐絯 2024-10-11 06:47:13

问题在于 POP3 没有锁定作业/消息的概念,因此同时登录同一帐户的多个客户端都将获得同一组消息。

然而,我必须解决类似的问题,这就是我实现它的方法。首先我使用 IMAP 而不是 POP3。然后,每个客户端在主收件箱下注册一个文件夹。然后,我有一个主节点来管理 INBOX 根文件夹。所有其他节点从主节点请求作业,主节点执行将作业从根收件箱简单移动到请求节点文件夹的操作。然后,节点可以直接从其私有文件夹中提取作业,而无需担心其他节点的干扰。

如果您想知道为什么需要主节点,那是因为 IMAP 没有原子移动操作,而是复制然后删除两阶段操作。这意味着为了防止任何类型的并发问题,您实际上仍然只能有一个线程/进程访问 INBOX 文件夹。

The problem is that POP3 has no concept of locking jobs/messages, so multiple clients logging into the same account at the same time will all get the same set of messages.

I had to solve a similar problem however, and this is how I achieved it. Firstly I used IMAP rather than POP3. Each client then registers a folder under the main inbox. I then have one master node that manages the INBOX root folder. All other nodes request a job from the master node which performs a simple move of the job from the root inbox to the requesting nodes folder. The node can then extract the job directly from its private folder without needing to worry about interference from other nodes.

If you were wondering on why there needs to be a master node it is because IMAP does not have an atomic move operation, but is rather a copy then delete two phase operation. This means that to prevent any sort of concurrency issues you can still really only have one thread/process accessing the INBOX folder.

jJeQQOZ5 2024-10-11 06:47:13

几年前我自己这样做了

我最终将消息的 UID 存储在具有 UNIQUE 约束的共享 SQL Server 表中。
在处理每条消息之前,将其添加到表中。
如果您遇到异常,则说明另一台机器已经捕获了该异常。

I did this myself a couple of years ago.

I ended up storing the messages' UIDs in a shared SQL Server table with UNIQUE constraint.
Before processing each message, add it to the table.
If you get an exception, a different machine already grabbed it.

夜司空 2024-10-11 06:47:13

当然这是可能的,尽管效率极低。由于 POP3 是轮询的,因此还会引入大量延迟。您为什么要这样分配工作量?你真正想解决什么问题?

Of course it's possible, although horribly inefficient. Because POP3 is polled, you'd also introduce a lot latency. Why would you want to distribute your workload like this? What are you really trying to solve?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文