RPC (Remote Procedure Call) remote procedure call, mainly to solve the problem of remote communication, does not need to understand the communication mechanism of the underlying network.
RPC framework
Thrift (FB) and dubbo (Ali) are well-known.
RPC generally requires 4 steps:
1. Establish communication
The first thing to do is to solve the communication problem: that is, if machine A wants to call machine B, it must first establish a communication connection, mainly by establishing a TCP connection between the client and the server.
2. Service addressing
To solve the addressing problem, how to connect server A to server B (such as host or IP address) and a specific port, the name of the method is what.
3. Network transmission
1) Serialization
When an application on server A initiates an RPC call, the calling method and parameter data need to be serialized first.
2) Deserialization
When server B receives the request of server A, it needs to deserialize the received parameters and other information.
4. Service call
The return value is obtained after the B server makes a local call (through proxy). At this time, the return value needs to be sent back to the A server. The same is also required After serialization, the binary data is sent back to the A server through network transmission.
Usually, a complete PRC call needs to go through the above 4 steps.
MQ (message queue)
Message queue (MQ) is a communication model that can realize one-way communication from producer to consumer. Generally speaking, it refers to the realization of this model Middleware.
Typical MQ middleware:
RabbitMQ, ActiveMQ, Kafka, etc.
Typical features:
1, decoupling
p>
2, reliable delivery
3, broadcast
4, final consistency
5, traffic peak cutting
6. Message delivery guarantee
7. Asynchronous communication (support synchronization)
8. Improve system throughput and robustness
Typical usage scenario: in the spike business Use MQ to achieve traffic peak clipping and application decoupling.
The difference and association between RPC and MQ
1. In terms of architecture, the difference between RPC and MQ is that Message has an intermediate node, Message Queue, which can store messages.
2. Synchronous call: For scenes that need to wait for the processing result to be returned immediately, RPC is the first choice.
3. The use of MQ, on the one hand, is based on performance considerations. For example, the server cannot respond quickly to the client (or the client does not require real-time response) and needs to be cached in the queue.
On the other hand, it focuses more on data transmission, so the methods are more diversified. In addition to peer-to-peer, it also has functions such as subscription and publishing.
4. And as the business grows, the processing volume of some processing ends will become a bottleneck, and synchronous calls will be transformed into asynchronous calls. At this time, you can consider using MQ.