当前位置: 首页 > news >正文

销售网站设计手机号注册的网站

销售网站设计,手机号注册的网站,免费网站电视剧下载,东莞网站建设制作公司排名SpringCloud 1.认识微服务 1.1单体架构 单体架构#xff1a;将业务的所有功能集中在一个项目中开发#xff0c;打成一个包部署 单体架构的优缺点#xff1a; **优点#xff1a;**架构简单#xff0c;部署成本低 **缺点#xff1a;**耦合度高#xff08;维护困难将业务的所有功能集中在一个项目中开发打成一个包部署 单体架构的优缺点 **优点**架构简单部署成本低 **缺点**耦合度高维护困难升级困难 1.2分布式架构 分布式架构根据业务功能对系统做拆分每个业务功能模块作为独立项目开发称为一个服务 **优点**降低服务耦合有利于服务升级和拓展 **缺点**服务调用关系错综复杂 分布式架构虽然降低了服务耦合但是服务拆分时也有很多问题需要思考服务拆分的粒度、服务之间调用、服务之间调用关系的管理需要制定一套行之有效的标准来约束分布式架构。 1.3微服务架构 微服务的架构特征 单一职责微服务拆分粒度小每一个服务都对应唯一的业务能力做到单一职责自治团队独立技术独立独立部署和交付面向服务服务提供统一标准的接口与语言和技术无关隔离性强服务调用做好隔离、容错、降级、避免出现级联问题 微服务是一种经过良好架构设计的分布式架构方案 SpringCloud是目前国内使用最广泛的微服务框架。官网地址https://spring.io/projects/spring-cloud SpringCloud集成了各种微服务功能组件并基于SpringBoot实现了这些组件的自动装配 其中常见的组件包括 服务注册发现Eureka、Nacos、Consul服务远程调用OpenFeign、Dubbo服务链路监控Zipkin、Sleuth统一配置管理SpringCloudConfig、Nacos统一网关路由SpringCloudGateway、Zuul流控、降级、保护Hystix、Sentinel SpringCloud是微服务交媾的一站式解决方案继承了各种优秀微服务功能组件 2.服务拆分 任何分布式架构都离不开服务的拆分微服务也一样 微服务的拆分原则 不同微服务不要重复开发相同的业务微服务数据独立不要访问其他微服务的数据库微服务可以将自己的业务暴露为接口供其他微服务调用 3.远程调用 项目结构 在order-service服务中有一个根据id查询订单的接口 package cn.itcast.order.web;import cn.itcast.order.pojo.Order; import cn.itcast.order.service.OrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController RequestMapping(/order) public class OrderController {Autowiredprivate OrderService orderService;GetMapping(/{orderId})public Order queryOrderByUserId(PathVariable(orderId) Long orderId) {// 根据id查询订单并返回return orderService.queryOrderById(orderId);} } 根据id查询订单返回值是Order对象,如图 在user-service中有一个根据id查询用户的接口 package cn.itcast.user.web; import cn.itcast.user.pojo.User; import cn.itcast.user.service.UserService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter;Slf4j RestController RequestMapping(/user) public class UserController {Autowiredprivate UserService userService;/*** 路径 /user/110** param id 用户id* return 用户*/GetMapping(/{id})public User queryById(PathVariable(id) Long id) {return userService.queryById(id);} }查询的结果如图 **案例需求**修改order-service中的根据id查询订单业务要求在查询订单的同时根据订单中包含的userId查询出用户信息一起返回 分析需要在order-service中向user-service发起一个http请求调用http://localhost:8081/user/{userId}接口 步骤 注册一个RestTemplate的实例到Spring容器修改order-service服务中的OrderService类中的queryOrderById方法根据Order对象中的userId查询User将查询的User填充到Order对象中返回 package cn.itcast.order.pojo; import cn.itcast.pojo.User; import lombok.Data; //Order实体类 Data public class Order {private Long id;private Long price;private String name;private Integer num;private Long userId;private User user; }package cn.itcast.order;import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate;MapperScan(cn.itcast.order.mapper) SpringBootApplication public class OrderApplication {public static void main(String[] args) {SpringApplication.run(OrderApplication.class, args);}Beanpublic RestTemplate restTemplate() {return new RestTemplate();} }实现远程调用 package cn.itcast.order.service;import cn.itcast.feign.UserClient; import cn.itcast.pojo.User; import cn.itcast.order.mapper.OrderMapper; import cn.itcast.order.pojo.Order; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;Service public class OrderService {Autowiredprivate OrderMapper orderMapper;Autowiredprivate RestTemplate restTemplate;public Order queryOrderById(Long orderId) {// 1.查询订单Order order orderMapper.findById(orderId);//2.调用user微服务接口根据userId得到用户信息String url http://userservice/user/ order.getUserId();User user restTemplate.getForObject(url, User.class);//3.封装user数据到orderorder.setUser(user);// 4.返回return order;} }
http://www.huolong8.cn/news/299735/

相关文章:

  • 罗湖中小网站建设湖州市城乡建设局网站
  • 建一个购物网站大约多少钱沈阳建设工程交易中心官网
  • 我的网站模板下载不了WordPress做app下载
  • 西安网站制作公司怎么选微商城开店
  • 网站建立的研究方案免费网站建设 优帮云
  • 南阳网站建设制作陕西 网站建设 陕ICP
  • 论坛类网站开发网站代理打开
  • 2003系统做网站网站后期维护管理
  • 可以将自己做的衣服展示的网站网页制作需要哪些软件
  • 北京网站开开发公司镇江seo网络推广定制
  • 网站建设要域名和什么花都网站建设
  • 广西建设网站网址多少钱网站模板制作与安装教程视频
  • 青海建设厅职称网站最便宜的网站
  • 产品网站免费模板网页设计实训总结和体会
  • 网站报价方案怎么做网站建设公司推荐q479185700顶上
  • 大型网站建设优化排名做psd模板下载网站
  • 二手书交易网站开发现状网站分享到朋友圈代码
  • 建德广元建设有限公司网站优秀的软文广告欣赏
  • 垂直汽车网站做电商的优势做各国民宿租赁的网站
  • 义乌网站建设现状免费的黄台app下载
  • 建公司网站的公司没有网站做淘宝客
  • 腾讯云快速建站上海网站建设 迈若
  • 国际物流网站制作模板南宁市网站开发建设
  • 2017网站开发语言排名pc端网站怎么做自适应手机端
  • 韶山网站建设做队徽的网站
  • 网站怎么做成小程序网站不兼容360浏览器
  • 排名好的郑州网站建设做app怎么做
  • 怎样免费推广网站菏泽正耀网站建设公司怎么样
  • 网站整合建设方案排版模板素材
  • 如何做网站不被坑企业国际网站建设