REST API 和消息传递 [英] REST APIs and messaging

查看:33
本文介绍了REST API 和消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个系统,它公开了一个 REST API,其中包含一组丰富的 CRUD 端点来管理不同的资源.REST API 也由使用 Ajax 执行调用的前端应用程序使用.

I have a system that exposes a REST API with a rich set of CRUD endpoints to manage different resources. The REST API is used also by a front-end application that executes calls by using Ajax.

我想让其中一些调用异步并增加可靠性.

I would like to make some of these calls asynchronous and add reliability.

显而易见的选择似乎是消息代理(ActiveMQ、RabbitMQ 等...).

The obvious choice seems a message broker (ActiveMQ, RabbitMQ, etc...).

以前从未使用过消息代理,我想知道是否可以将它们置于"REST API 之前而无需重写它们.

Never used message brokers before and I am wondering if they can be "put in front of" the REST API without having to rewrite them.

我不想仅通过消息传递系统访问 REST API:对于某些端点,调用必须始终是同步的并且可靠性不太重要(主要是因为如果出现错误,用户会立即收到反馈).

I do not want to access the REST API only through the messaging system: for some endpoints, a call must always be synchronous and the reliability is less important (mainly because in case of error the user receives an immediate feedback).

完整 ESB 是否是此用例的更好选择?

Would a full ESB be a better option for this use case?

推荐答案

如果我理解您的问题,您希望将 API 端点注册"为订阅者,以便它可以接收发送到给定队列的消息.

If I understand your question, you would like to "register" an API endpoint as a subscriber so that it could receive the messages sent to a given queue.

我不认为可以配置消息代理来执行此操作.

I do not think that a message broker can be configured to do this.

例如,如果您想使用消息代理,您的生产者和订阅者都需要使用 JMS API.

For example, if you want to use a message broker, both your producers and subscribers need to use the JMS API.

我不知道是否有解决方案可以实现将执行相应 API 调用的订阅者.在这种情况下,可靠性会受到影响,因为消息将在 API 调用执行之前出列.如果订阅者在 API 的同一进程中运行是有意义的,但在这种情况下,不清楚为什么应该使用 REST API 而不是库.

I do not know if a solution can be to implement a subscriber that will execute the corresponding API call. In this case, the reliability is compromised because the message will be dequeued before the API call is executed. It can make sense if the subscriber is running in the same process of the API, but in this case it is not clear why you should use a REST API instead of a library.

这篇关于REST API 和消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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