在其他一切正常的情况下处理离线数据库?

发布于 2024-12-09 18:31:09 字数 370 浏览 0 评论 0原文

我有一个 Windows 服务,可以监视多个邮箱中的新邮件。一旦新邮件到达,该服务负责确定如何处理它。它可以解析它并将其输入数据库,忽略它,或者如果它无法识别它,则将其转发给某人。

我已经有了一个有效的实现,如果/当我们的电子邮件服务器出现故障时,该服务将尝试每 n 分钟重新连接一次,直到成功。另一个问题是如果/当数据库服务器出现故障时会发生什么。我们的服务很可能仍在运行并解析电子邮件,但如果数据库插入失败,就会停止。

如何处理数据库宕机?我没有让我的服务负责与数据库交互,而是使用像 NServiceBus 这样的消息传递框架,并为每个需要添加的新项目发送消息。然后该服务将尝试处理它。如果由于某种原因处理失败(很可能是数据库已关闭),只需将项目留在队列中以供稍后处理?

I have a Windows service that monitors several mailboxes for new mail. Once new mail arrives the service is responsible for determining what to do with it. It can either parse it and enter it into a database, ignore it, or forward it to someone if it doesn't recognize it.

I already have a working implementation if/when our email server goes down where the service will try and reconnect every n minutes until successful. The other problem is what happens if/when the database server goes down. Our service could very well still be running and parsing email but would stall if the database insertion fails.

How do I handle the database going down? Instead of having my service responsible for interacting to the database do I use a messaging framework like NServiceBus and send messages for each new item that needs to get added. Then this service would try and process it. If the processing fails for whatever reason (most likely the database is down) simply leave the item in the queue to process for later?

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

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

发布评论

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

评论(1

凉世弥音 2024-12-16 18:31:10

一种可能性:

如果数据库已关闭,则将已完成的工作序列化为 XML 或二进制格式,并将其存储在文件系统上(如果数据库已关闭)。将此视为离线队列。当数据库恢复时,让进程反序列化数据,然后将其存储在数据库中。

这样您仍然可以考虑处理数据并稍后插入。队列(备份)是文件系统。

One possibility:

If the database is down, serialize the completed work to XML or binary format and store it on the file system if the database is down. Consider this the offline queue. When the database comes back up, have the process de-serialize the data back and then store it in the database.

That way you can still consider the data processed and insert it at a later time. The queue (back up) is the file system.

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