[Microservice Study Notes] Understanding Microservices

[Microservice Study Notes] Understanding Microservices

monolithic architecture

insert image description here

distributed architecture

insert image description here

microservice architecture

insert image description here

SpringCloud

insert image description here

Service Splitting and Considerations

insert image description here

Case demo of service splitting

The databases of each service are independent of each other. You cannot directly access the database of the other party, and you can only initiate remote calls from one service to another.

insert image description here

Initiate a request for user query in the service of the order module

Register the RestTemplate in the entry class in the Order-Service module and use it to send http requests

insert image description here

In the page for querying orders, inject the restTemplate variable, and then use it to send http requests to query users

 public Order queryOrderById(Long orderId) {
    
    
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        // 创建url
        String url = "http://localhost:8081/user/" + order.getUserId();

        // 发哦是那个http请求  实现远程调用
        User user = restTemplate.getForObject(url,User.class);

        // 封装user到Order
        order.setUser(user);

        // 返回user
        return order;


        // 4.返回
//        return order;
    }

server and consumer

insert image description here

Guess you like

Origin blog.csdn.net/qq_44653420/article/details/132424826