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

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

问题描述

我有一个系统,该系统公开了具有丰富CRUD端点集的REST API,以管理不同的资源. REST API也被使用Ajax执行调用的前端应用程序使用.

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

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

以前从未使用过消息代理,我想知道它们是否可以放在" REST API的前面而不必重写它们.

我不想仅通过消息传递系统访问REST API:对于某些终结点,调用必须始终是同步的,并且可靠性不太重要(主要是因为在发生错误的情况下,用户会立即收到反馈)./p>

对于此用例,完整的ESB是否会是一个更好的选择?

解决方案

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

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

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

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

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.

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

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.

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).

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

解决方案

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.

For example, if you want to use a message broker, both your producers and subscribers need to use the JMS 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天全站免登陆