RESTful v/s MQ. Differences and other key features apart from Guaranteed Delivery

后端 未结 3 1147
悲哀的现实
悲哀的现实 2021-02-01 03:50

Ok..So I have started studying about MQ and its purpose/usecase etc... My existing application (Web made using JSP etc..) uses RestFUL interface to communicate with a remote ser

相关标签:
3条回答
  • 2021-02-01 04:37

    Both are abstractions but on different levels Your application can provide RESTful API, but under the hood it will utilize various components, among which is message queues.

    Short and dirty: RESTful declares best practices how to build app or components, MQ served for messaging between components.

    You may be confused with RPC, but in a web context it's not the same as MQ.

    0 讨论(0)
  • Both REST and MQ enable communicate between remote systems (and local).

    In a REST communication the consumer and the REST service provider should be running for a communication to succeed. It is a point to point communication.

    In MQ model the producer and consumer need not be running at the same time. The producers and consumers do not interact directly. The message broker takes care of handling the messages, persisting, it etc. Both point to point and publish-subscribe models are supported. In a publish subscribe model a message can be consumed by more than one consumer.

    These are just some basic points that differentiate them. There are enough posts on SO that talk about REST and MQ.

    0 讨论(0)
  • 2021-02-01 04:47

    One of the biggest differences is that REST implies synchronous processing while MQ is more often asynchronous. As you already mentioned, MQ is a way to decouple producer and consumer so that they don't have to be online at the same time but the system would still be functioning as a whole. If your use case implies a low-latency response (like a user with a browser) you need synchronous semantics and in this case MQ is just a different protocol. If latency is not a concern, or there's messaging goes only in one direction MQ may be a very viable alternative. One thing MQ provides for free is load balancing (and some level of HA) on the consumer side.

    REST is much more flexible in terms of client/server compatibility. You can run a REST client nearly on every platform, which is not the case with MQ. I guess, this is the reason why some people claim MQ is getting obsolete. For this reason MQ is not good for public APIs. However, for communication between two server systems MQ still remains a very good option. A unique feature of REST is that it allows you to fully mimic the WEB behavior of your resources (hypermedia), i.e. one resource contains a reference to the other and so on. MQ cannot provide anything like that.

    Performance may be another concern. I cannot give any exact figures, but MQ tends to have greater throughput.

    In some rare cases due to security requirements clients cannot connect directly to the server. In such cases MQ is pretty much the only way to send data to the server.

    To summarize, as a rule of thumb I would use REST

    • for public APIs or
    • where synchronous processing is needed

    MQ

    • when only a limited amount of server side systems is involved and
    • asynchronous processing is acceptable or
    • REST performance is not enough
    0 讨论(0)
提交回复
热议问题