Communication of Microservices

In the microservice architecture, the communication between services usually adopts a lightweight communication method. Lightweight generally refers to a language platform-independent protocol.

Synchronous and Asynchronous Communication

Message delivery, divided into synchronous message delivery and asynchronous message delivery

Scenarios for synchronous messaging:

When the message sender expects to receive a response within a certain time frame, then proceed to the next task. Basically he blocks until he receives a response

Scenarios for asynchronous messaging:

The sender does not require an immediate response, nor does it block the entire process. The response is optional, the sender does the rest

RPC(Remote Procedure Call)

RPC refers to remote procedure call. There are two servers, A and B. One service is deployed on server A. If you want to call the functions and methods provided by the application on server B, because there is no longer a memory space, you cannot call it directly. You need to go through the network. Just like calling a local method, call the function or method of the B service. The above call mechanism may lead to a high degree of coupling between the various systems

RESTFUL

Taking resources as the core can keep the application stateless, which is beneficial to the horizontal scaling of the cluster, but how to standardize the resource structure between systems or functions to ensure that various and standard requests from all parties can be accepted.

JMS(Java Message service)

JMS messages have two message types: queues and topics, support things, and can customize message formats (message headers, attributes, content)

queues production/consumer mode
  1. 消息生产者生产消息发送到queues中,然后消息消费者从queues中取出并且消费消息
    
  2. 消息被消费以后,queue中不再有存储,所以消息消费者不可能消费到已经被消费的消息
    
  3. queue支持存在多个消费者,但是对于一个消息而言,只会有一个消费者可以消费
    
Topic publish/subscribe model

A message producer publishes a message to a topic, and multiple message consumers subscribe to the message at the same time, and the message published to the topic will be subscribed and consumed by all subscribers

Reference: Microservice Architecture and Practice - Wang Lei

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324982303&siteId=291194637