听起来像是任何类型的工作队列都会做你需要的东西; 我个人非常喜欢使用 < a href=" http://dis.io/" rel=" nofollow noreferrer" >Redis 来做这类事情。 由于 Redis 列表维持插入顺序, 您可以简单地使用 < a href=" http://redis.io/ commanders/ lpush > rel=" nofollow noreferr" >LPUSH 您的 RPC调用的信息到列表末尾的列表末尾, 从任何数个网络服务器收听 RPC 呼叫的列表中, 到其他地方( 在另一个进程/另一机器上,我假设) < a href="http://redis.io/commands/rpop" rel= " nofol noreferr" > RPOP (或 < a href= "http://redis.io/comges/bpo" rel= " no referrrerererer> > BRPOP < BRPOP < /// a>)
由于 Node.js 完全使用非同步的 IO, 假设你没有在 RPC 听众中做很多处理( 也就是说, 您只听请求, 发送 ACK, 并按住 Redis ), 我猜测, 节点在这一点上会非常有效 。
除了在队列中使用 Redis 以外: 如果您想要确保, 在灾难性失败的情况下, 工作不会丢失, 您需要执行更多一些逻辑; 从 < a href=" http:// redis.io/ commands/rpopplpush" rel= “ nofollow noreferrer" > RPOPLPUSH a > 文件 :
<强力 > 陪审员:可靠的排队 强 >
Redis is often used as a messaging server to implement processing of background jobs or other kinds of messaging
tasks. A simple form of queue is often obtained pushing values into a
list in the producer side, and waiting for this values in the consumer
side using RPOP (using polling), or BRPOP if the client is better
served by a blocking operation.
However in this context the obtained
queue is not reliable as messages can be lost, for example in the case
there is a network problem or if the consumer crashes just after the
message is received but it is still to process.
RPOPLPUSH (or
BRPOPLPUSH for the blocking variant) offers a way to avoid this
problem: the consumer fetches the message and at the same time pushes
it into a processing list. It will use the LREM command in order to
remove the message from the processing list once the message has been
processed.
An additional client may monitor the processing list for
items that remain there for too much time, and will push those timed
out items into the queue again if needed.