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

响应式旅行社展业网站开发调研报告wordpress自定义编辑器

响应式旅行社展业网站开发调研报告,wordpress自定义编辑器,做视频up主视频网站,网页制作与网站建设 论文说明#xff1a;Sentinel是阿里巴巴开发的微服务治理中间件#xff0c;可用于微服之间请求的流量管控、权限控制、熔断降级等场景。本文介绍如何在Spring Cloud项目中整合Sentinel#xff0c;以及Sentinel的简单使用。 环境 首先搭建一个简单的微服务环境#xff0c;有以…说明Sentinel是阿里巴巴开发的微服务治理中间件可用于微服之间请求的流量管控、权限控制、熔断降级等场景。本文介绍如何在Spring Cloud项目中整合Sentinel以及Sentinel的简单使用。 环境 首先搭建一个简单的微服务环境有以下两个服务 订单服务查询订单并调用用户服务查询用户信息 用户服务查询用户信息 创建以下三个模块分别对应订单服务、用户服务和公共模块存储POJO对象 Common模块 Order类 import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor;Data AllArgsConstructor NoArgsConstructor public class Order implements java.io.Serializable {/*** 订单ID*/private String id;/*** 订单名称*/private String name;/*** 用户ID*/private String userId; }User类 import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor;Data AllArgsConstructor NoArgsConstructor public class User implements java.io.Serializable {/*** 用户ID*/private String id;/*** 用户名*/private String username;/*** 密码*/private String password; }pom.xml文件 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.hezy/groupIdartifactIdsentinel_demo/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdcommon/artifactIdpropertiesmaven.compiler.source11/maven.compiler.sourcemaven.compiler.target11/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/properties/projectUserService模块 UserController类 import com.hezy.pojo.User; import com.hezy.service.UserService; import org.springframework.beans.factory.annotation.Autowired; 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(/user) public class UserController {Autowiredprivate UserService userService;GetMapping(/getUser/{id})public User getUser(PathVariable String id) {return userService.getUserById(id);} }UserService类 import com.hezy.pojo.User;public interface UserService {User getUserById(String id); }UserService实现类 import com.hezy.mapper.UserMapper; import com.hezy.pojo.User; import com.hezy.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;Service public class UserServiceImpl implements UserService {Autowiredprivate UserMapper userMapper;Overridepublic User getUserById(String id) {return userMapper.getUserById(id);} }UserMapper import com.hezy.pojo.User; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select;Mapper public interface UserMapper {Select(select * from tb_user where id #{id})User getUserById(String id); }启动类 import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication MapperScan(com.hezy.mapper) public class Start {public static void main(String[] args) {SpringApplication.run(Start.class, args);} }application.yml配置文件 server:port: 8081# 1.数据源的配置 spring:# 设置微服务名称application:name: userservice# 数据库配置datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/sentinel_demo?useUnicodetruecharacterEncodingutf-8useSSLfalseserverTimezoneGMT%2B8username: rootpassword: 123456cloud:nacos:server-addr: localhost:8848# 2.mybatis配置 mybatis:configuration:# 显示SQL日志配置log-impl: org.apache.ibatis.logging.stdout.StdOutImpl# 驼峰命名配置map-underscore-to-camel-case: true# 设置mapper.xml文件所在的路径mapper-locations: classpath:mapper/*.xml说明有些配置可能并不需要如Mybatis日志相关配置而有些配置需要自适应修改如nacos服务器地址mysql数据库地址 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.hezy/groupIdartifactIdsentinel_demo/artifactIdversion1.0-SNAPSHOT/version/parentartifactIduserservice/artifactIdpropertiesmaven.compiler.source11/maven.compiler.sourcemaven.compiler.target11/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencies!--web依赖--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!--druid连接池依赖--dependencygroupIdcom.alibaba/groupIdartifactIddruid-spring-boot-starter/artifactIdversion1.2.8/version/dependency!--mysql驱动--dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependency!--mybatis依赖--dependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion2.2.2/version/dependency!-- nacos客户端依赖包 --dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependency!--公共模块--dependencygroupIdcom.hezy/groupIdartifactIdcommon/artifactIdversion1.0-SNAPSHOT/version/dependency/dependencies/projectOrderService模块 OrderController类 import com.hezy.service.OrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;RestController RequestMapping(/order) public class OrderController {Autowiredprivate OrderService orderService;GetMapping(/getOrder/{id})public String getOrder(PathVariable String id) {return orderService.getOrderById(id).toString();} }OrderService类 public interface OrderService {String getOrderById(String id); }OrderService实现类 import com.hezy.feignclients.UserServiceClient; import com.hezy.mapper.OrderMapper; import com.hezy.pojo.Order; import com.hezy.pojo.User; import com.hezy.service.OrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;Service public class OrderServiceImpl implements OrderService {Autowiredprivate OrderMapper orderMapper;Autowiredprivate UserServiceClient userServiceClient;Overridepublic String getOrderById(String id) {// 查询用户信息User userById userServiceClient.getUserById(1);// 查询订单信息Order orderById orderMapper.getOrderById(id);return 用户信息 userById 订单信息 orderById;} }OrderMapper import com.hezy.pojo.Order; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select;Mapper public interface OrderMapper {Select(select * from tb_order where id #{id})Order getOrderById(String id); }UserServiceClient类 import com.hezy.pojo.User; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam;FeignClient(name userservice) public interface UserServiceClient {GetMapping(/user/getUser/{id})User getUserById(RequestParam String id); }启动类 import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients;SpringBootApplication MapperScan(com.hezy.mapper) EnableFeignClients(com.hezy.feignclients) public class Start {public static void main(String[] args) {SpringApplication.run(Start.class, args);} }说明注意EnableFeignClients()中的配置的是feignclient所在的包路径即UserServiceClient所在的包 application.yml server:port: 8082# 1.数据源的配置 spring:# 设置微服务名称application:name: orderservice# 数据库配置datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/sentinel_demo?useUnicodetruecharacterEncodingutf-8useSSLfalseserverTimezoneGMT%2B8username: rootpassword: 123456cloud:# nacos配置nacos:server-addr: localhost:8848# 2.mybatis配置 mybatis:configuration:# 显示SQL日志配置log-impl: org.apache.ibatis.logging.stdout.StdOutImpl# 驼峰命名配置map-underscore-to-camel-case: true# 设置mapper.xml文件所在的路径mapper-locations: classpath:mapper/*.xmlpom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.hezy/groupIdartifactIdsentinel_demo/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdorderservice/artifactIdpropertiesmaven.compiler.source11/maven.compiler.sourcemaven.compiler.target11/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencies!--web依赖--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!--druid连接池依赖--dependencygroupIdcom.alibaba/groupIdartifactIddruid-spring-boot-starter/artifactIdversion1.2.8/version/dependency!--mysql驱动--dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependency!--mybatis依赖--dependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion2.2.2/version/dependency!--公共模块--dependencygroupIdcom.hezy/groupIdartifactIdcommon/artifactIdversion1.0-SNAPSHOT/version/dependency!-- nacos客户端依赖包 --dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependency!--feign客户端依赖--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-openfeign/artifactId/dependency/dependencies /projectsentinel-demo父模块 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.3.9.RELEASE/versionrelativePath//parentgroupIdcom.hezy/groupIdartifactIdsentinel_demo/artifactIdversion1.0-SNAPSHOT/versionpackagingpom/packagingmodulesmoduleuserservice/modulemoduleorderservice/modulemodulecommon/module/modulespropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingjava.version11/java.versionspring-cloud.versionHoxton.SR8/spring-cloud.versionmysql.version5.1.47/mysql.versionmybatis.version2.1.1/mybatis.version/propertiesdependencyManagementdependencies!-- springCloud --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependency!--nacos的管理依赖--dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-alibaba-dependencies/artifactIdversion2.2.5.RELEASE/versiontypepom/typescopeimport/scope/dependency!-- mysql驱动 --dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion${mysql.version}/version/dependency!--mybatis--dependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion${mybatis.version}/version/dependency/dependencies/dependencyManagementdependenciesdependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency/dependencies/project说明注意版本控制dependencyManagement标签中的内容不加子模块中的sentinel依赖可能不生效 数据库 数据库中对应的表数据如下 运行 启动正常 nacos注册正常 访问正常 整合Sentinel 项目 在此之上在调用方订单服务orderservice加入下面的依赖 !--sentinel-- dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-sentinel/artifactId /dependency配置文件中添加sentinel控制台地址暂时为本地下面我们在本地启动sentinel服务 spring:cloud:sentinel:transport:dashboard: localhost:8080说明注意层级结构 sentinel服务 可在 Github中将sentinel的jar包下载下来通过运行jar包的方式来启动sentinel服务器 在jar包所在的目录打开命令窗口使用jar -jar 的方式启动如下 启动完成后在浏览器中输入http://localhost:8080/可进入sentinel控制台初始账号密码sentinel/sentinel 使用 登录进去后接着我们重启前面的两个服务再次访问查询订单的接口触发一次由订单服务向用户服务的请求即可在sentinel控制台左侧看到订单服务的菜单栏 上面就是针对订单服务的一系列功能比如我们想对订单服务进行流量控制可通过下面的操作实现 可在 流控规则 中查看到我们新增的这条规则 这个时候我们快速点击刷新页面可以观察到请求失败的情况但需要注意失败不是持久的而是1秒内超过2次请求才会失败如果1秒点两次1秒点两次则不会失败。 我们可以使用Apifox进行自动化测试如下我们设置10次请求每次请求后停顿200ms 运行查看结果。状态码200是正常的状态码429是失败的。可以看到有周期性失败的请求这些就是请求过于频繁即触发了流控规导致失败的请求。 说明 本文介绍了Sentinel在微服务项目中的整合及简单使用
http://www.hkea.cn/news/14526343/

相关文章:

  • 东莞建站模板代理电子商务网站建设中应注意哪些问题
  • 静态网站怎么做百度推广网页设计教程这本书讲什么
  • 北京网站手机站建设公司电话wordpress更改文章宽度
  • 我的世界有什么做的视频网站网站建设中啥意思
  • 上海模板建站多少钱自建网站工具
  • 网站备案密码找回中建三局招聘出国务工
  • 石家庄市栾城区建设局网站app网站的电话是什么
  • 网站设计深圳公司网站建设 技术可行性
  • 北海市网站建设一般通过男网友
  • 如何建设网站站点东莞标志设计公司
  • 京东第一次做网站网络项目资源网
  • 画廊网站建设wordpress 取一类文章
  • 做网站可以使用rem单位吗网站点击排名优化
  • 网站换域名做301六安网站建设找哪家
  • 跨境电商网站建设开发杭州点餐app开发
  • 青海格尔木建设局网站免费空间做淘宝客网站
  • 网站的会员系统怎么做wordpress 轻博客主题
  • 哪个网站可以做身份核验温州捷创网站建设
  • 辽宁营销型网站建设云南省城乡建设厅网站
  • 浙江建设信用网新网$网站优化
  • 怎么优化网站关键词网站及网页设计费用
  • 德保网站建设研究生培训机构排名
  • 美食分享网站怎么做网站关键词和网页关键词的样本
  • 随州网站建设有限公司网站建设 电子政务
  • 莱芜钓鱼网站什么网站可以免费发布招聘信息
  • 网站内的搜索怎么做的wordpress模板wiki
  • 南京电商网站建设公司排名中江县 网站建设
  • 开发电子商务网站的主流语言搜狗搜索引擎优化论文
  • 网站开发框架的主要作用大连招聘网最新招聘
  • 网站建设公司提成网站色彩策划