英文:
How to design a system with pub/sub with time-based coordination
问题
我正在为发布/订阅模型的高级设计工作,其中订阅者应该不会在指定时间之前处理消息。例如,假设一组股票订单需要在预定义的到期日期精确取消。假设我们有一个消息队列,每个消息都包含需要取消的订单信息。队列是有优先级的,以便到期时间最接近当前时间的消息位于队列的前面。
显然,我们不希望订阅者尽可能快地工作并立即取消订单。我们只希望在消息的到期时间等于或小于当前时间时才从队列中取出消息。
是否有支持这种用例的分布式消息队列?以便它会阻塞消费者直到特定时间才能读取消息?或者我是否完全以不合理的方式处理这个问题?
英文:
I am working on a high-level design for a pub/sub model where the subscribers should not process messages until a specified time. For example, let's say a set of stock orders need to be cancelled exactly at some predefined expiration datetime. Let's say we have a message queue where each message has information on the order that needs to be cancelled. The queue is prioritized so that the messages with expiration time closest to the current time is at the head of the queue.
We obviously don't want the subscribers to work as fast as possible and cancel orders immediately. We want to only take the message from the queue if its expiration time is equal to or less than the current time.
Are there distributed message queues that support this use case? So that it blocks consumers from reading until a certain time? Or am I approaching this problem in an unreasonable way altogether?
答案1
得分: 1
AWS Step Functions可用于此目的。您可以定义一个Wait
状态,接收带有时间戳的输入参数,一旦达到该时间戳,它将调用您定义的Task。
例如:
我不知道它在内部如何工作,但我想象它会将消息放入主队列,而轮询器会不断从该队列中读取消息。如果currentTime < messageTimestamp
,那么它会将其放回,否则它会放入一个不同的队列,供实际处理这些消息的工作程序接收。
英文:
AWS Step Functions could be used for this. You define a Wait
state that receives an input parameter with a timestamp, and once that timestamp is hit, it will call a Task that you define.
For example:
I don't know how this works under the hood, but I'd imagine it puts messages in a main queue, and a poller continually reads messages off this queue. If currentTime < messageTimestamp
then it puts it back, otherwise it puts to a different queue which is meant to be picked up by workers that actually do things with those messages.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论