首页 > 解决方案 > 当数据到达过期时间时向 RabbitMQ 发布事件

问题描述

我目前正在使用事件驱动的架构。我们有一些数据在我们的数据库中有过期时间。什么是在数据过期的确切时刻发布事件(数据过期)的最佳解决方案?我想实时执行此操作,而不是执行调度程序进程或批处理。

标签: eventsarchitecturerabbitmqmicroservices

解决方案


I think to achieve that you will need the DB to have some mechanism to support that. And I can't think of any right now (even less without knowing which DB).

But from the top of my head, I can say: if that expiration date is never modified after being inserted in DB, you could just insert a message in RabbitMQ at the same moment that you insert the data in DB. You would set a TTL in the message, and configure dead lettering in that queue. That way, when the message expires it gets automatically published to another exchange.

You can read more here: https://www.rabbitmq.com/dlx.html


推荐阅读