是什么最佳方法来调查MongoDB数据库寻找更改

发布于 2025-02-08 03:42:20 字数 386 浏览 3 评论 0原文

我有两个微服务(Servicea和ServiceB)。

  • Servicea将记录插入到MongoDB数据库中。
  • ServiceB在MongoDB中检查是否有新记录,并且对这些新记录进行了一些工作。

ServiceB是一个背景服务,在executeasync方法中,我查询MongoDB每秒检查新记录。

是每秒查询数据库的好方法吗? (这不是资源密集型吗?它是一个有条件的选择)

,否则,我正在考虑使用兔子:

  • servicea inserts记录在mongodb数据库中,然后将消息(记录的ID)推向兔子。
  • ServiceB消耗RabbitMQ的消息并确实有效。

I have two microservices (ServiceA and ServiceB).

  • ServiceA inserts records into a MongoDB database.
  • ServiceB check in MongoDB if there are new records and does some work with theses new records.

ServiceB is a backgroundservice, in ExecuteAsync method, I query MongoDB to check new records every second.

Is it a good approach to query the database every second? (Is it not too resource intensive? It's a select with where condition)

Otherwise, I was thinking of using RabbitMQ:

  • ServiceA inserts records in MongoDB database and pushes message (Id of record) to RabbitMQ.
  • ServiceB consumes RabbitMQ's message and does work.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文