为什么在使用 webhooks 时需要队列? [英] Why do we need a queue when using webhooks?

查看:29
本文介绍了为什么在使用 webhooks 时需要队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下使用 queue 的目的是什么?

Can anyone clarify what is the purpose of using queue ?

我的理解是 webhook 只是一个 URL ,你向那个 URL 发出一个 POST 请求> 然后根据请求的正文/数据做一些事情.那么为什么我需要将数据排队并将其存储在 database 中,然后再次遍历数据库并执行这些操作.

What i understand is that a webhook is just a URL , you do a POST request to that URL and then do some stuff based on the body/data of the request. So why i need to queue the data and store it in a database then loop through the database again and perform the stuff.

推荐答案

简而言之,您不必使用队列.Webhook 只是一个 HTTP 请求(通常是 POST),通知您的应用程序某种类型的事件.您可能想要考虑队列的原因是您可能会遇到的典型问题.

The short answer is, you don't have to use a queue. A webhook is just an HTTP request (typically POST) notifying your application of some type of event. The reason you might want to consider a queue is because of typical issues you could run into.

其中之一是因为返回到 webhook 请求者的响应时间(来源).许多来源希望尽快得到响应(HTTP 状态 200),以便他们可以从 Webhook 系统中取出请求.如果处理 Webhook 需要一些时间,则消息来源通常会建议您使用队列来延迟与 Webhook 的 200 响应异步的较长过程.

One of these is because of response time back to the webhook requester (source). Many sources want a response (HTTP status 200) as quickly as possible so they can dequeue the request from their webhook system. If processing the webhook takes some time, a source will typically advise you to use a queue to defer the lengthier process asynchronous to the 200 response to the webhook.

另一个可能的原因可能是删除重复请求.Webhook 不能保证您在每个事件中只会收到一个请求.队列可用于消除这些请求的重复数据.

Another possible reason could be for removing duplicate requests. There is no guarantee with webhooks that you will only receive a single request per event. A queue can be used to de-dupe these requests.

如果可能,我建议您坚持使用简单的请求处理程序,然后在遇到问题时开发更复杂的处理程序.如果您遇到上述问题,请将队列视为一种潜在的设计方法.

I would recommend you stick with a simple request handler if possible, then evolve a more sophisticated handler if you run into issues. Consider queues as a potential design approach if you run into issues like those above.

这篇关于为什么在使用 webhooks 时需要队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆