官术网_书友最值得收藏!

Direct messaging

In direct messaging, each request is sent directly to the microservice on its API endpoint. Such requests may be initiated by users, applications, or by other microservices that integrate with the target microservice to complete a particular task. Mostly the endpoints to handle such requests are implemented using REST (https://en.wikipedia.org/wiki/Representational_state_transfer), which allows resource identifiers to be addressed directly via HTTP based APIs with a simple messaging style.

REST is an architectural style with predefined operations based on HTTP request methods, such as GET, PUT, POST, and DELETE. The stateless nature of REST makes it fast, reliable, and scalable with multiple components. 

For example, in a typical microservices-based e-commerce application, an administrative user may wish to create, update, or manage users via the User Service's REST endpoint. In that case, the user can directly call the REST API of the User Service, as shown in the following diagram:

Similarly, a mobile application may want to query user interests via Interest Service's REST endpoint of the e-commerce application. Since the Interest Service depends on both the User Service and the Orders Service, it may further initiate two separate calls to the REST endpoint of these two services to get the desired response which it can merge with the user interests data and generate the response for the requesting application. Mostly, all these kinds of request-response are synchronous in nature as the sender expects a response with the results in the same call. Asynchronous requests are mostly used to send alerts or messages to record an operation, and in those cases, the sender doesn't wait for the response and expects the action to be taken eventually.

Avoid building long chains of synchronous calls as that may lead to high latency and an increased possibility of failure due to multiple hops of intermediate requests and network round-trips among the participating services.

Message formats used with REST endpoints are mostly text-based message formats such as JSON, XML, or HTML, as supported by the endpoint implementation. Binary message formats such as Thrift (https://en.wikipedia.org/wiki/Apache_Thrift)ProtoBuf (https://en.wikipedia.org/wiki/Protocol_Buffers), and Avro (https://avro.apache.org/) are also popular due to their wide support across multiple programming languages.

Use direct messaging only for smaller microservices-based deployments. For larger deployments, it is advisable to go with API gateways that act as the main entry point for all clients. Such API gateways help monitor requests for microservices and also assist in the maintenance and upgrade operations.
主站蜘蛛池模板: 新津县| 三明市| 潜江市| 鲜城| 鱼台县| 桃园县| 正安县| 汽车| 长海县| 大庆市| 广饶县| 昌图县| 湖州市| 开江县| 行唐县| 开平市| 巧家县| 高要市| 桐庐县| 高邑县| 灵寿县| 旬邑县| 尚义县| 新和县| 杭锦旗| 平南县| 云和县| 台中县| 建昌县| 商丘市| 高台县| 神池县| 安康市| 和政县| 肥东县| 乌拉特后旗| 江北区| 图片| 随州市| 宁强县| 南平市|