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

企业网站建设服务好商务定制网站

企业网站建设服务好,商务定制网站,wordpress默认字体改黑色,科技软件公司网站模板目录 一.启动nacos和redis 1.查看是否有nacos和redis 二.开始项目 1.hystrix1工程(修改一下工程的注册名字) 2.运行登录nacos网站查看运行效果(默认密码nacos,nacos) 3.开启第二个项目 hystrix2工程 4.关闭第二个项目 hyst…

目录

一.启动nacos和redis

1.查看是否有nacos和redis

 二.开始项目

1.hystrix1工程(修改一下工程的注册名字)

2.运行登录nacos网站查看运行效果(默认密码nacos,nacos) 

3.开启第二个项目 hystrix2工程

4.关闭第二个项目 hystrix2工程 (模拟熔断)

三.应用hystrix

1.在第一个工程里hystrix1添加依赖

2.开启Hystrix

 3.修改第一个项目hystrix1的工具类Result

4.修改第一个项目hystrix1的控制类

 5.修改第一个项目hystrix1的application.yml文件

6.先同时启动两个项目,在postman进行测试 

3.6.1连接成功的情况

3.6.2连接失败的情况(提示) 

四.添加仪表盘(很少用到,了解)

1.在第一个工程里hystrix1添加依赖

 2.添加配置类(固定写法)

3.启动类添加注解@EnableHystrixDashboard

4启动项目,访问如下地址

​编辑 五.我的项目结构

1.第一个工程hystrix1

2.第一个工程hystrix2


 

一.启动nacos和redis

1.查看是否有nacos和redis

docker ps -a

2.启动nacos和redis 

docker start nacos
docker start redis-6379
docker ps

 二.开始项目

这里用的项目过程在我的另一个博客中OpenFeign微服务部署-CSDN博客

我是粘贴复制后重写的名字,hystrix1对应SpringSessiondemo,hystrix2对应SpringSessiondemo1,

hystrix2工程(没有代码改变)先启动之后断开(模拟宕机),

1.hystrix1工程(修改一下工程的注册名字)

2.运行登录nacos网站查看运行效果(默认密码nacos,nacos) 

3.开启第二个项目 hystrix2工程

用postman测试

4.关闭第二个项目 hystrix2工程 (模拟熔断)

三.应用hystrix

1.在第一个工程里hystrix1添加依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

2.开启Hystrix

在第一个工程里hystrix1的启动类上添加开启Hystrix的注解

@EnableHystrix

 此时完成上述两个操作后,再次关闭第二个工程里hystrix2,页面也是报错,但不是“连接超时”的错误,而是“熔断类型”的错误。为了让用户体验度好一些,报错信息不暴露给用户,我们完成下面的编码。

 3.修改第一个项目hystrix1的工具类Result

package com.jr.util;import lombok.Data;import java.util.HashMap;
import java.util.Map;@Data
public class Result {private Integer code;private String message;private Map<String, Object> map = new HashMap<>();private Result() {}public static Result ok() {Result r = new Result();r.setCode(ResultCode.SUCCESS.getCode());r.setMessage(ResultCode.SUCCESS.getMessage());return r;}public static Result error() {Result r = new Result();r.setCode(ResultCode.ERROR.getCode());r.setMessage(ResultCode.ERROR.getMessage());return r;}public Result setMessage(String message) {this.message = message;return this;}public Result put(String key, Object value) {map.put(key, value);return this;}public Object get(String key) {return map.get(key);}}

 

4.修改第一个项目hystrix1的控制类

package com.jr.controller;import com.jr.entry.UserDto;
import com.jr.service.IUserService;
import com.jr.util.Result;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.tomcat.jni.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/user")
public class UserController {@Autowiredprivate IUserService userService;@GetMapping@HystrixCommand(fallbackMethod = "infoHystrix") //一旦熔断了,就去执行infoHystrix方法。public Result info() {UserDto user = userService.info();return Result.ok().put("data", user);}public Result infoHystrix() {return Result.error().setMessage("被熔断了");}@GetMapping("/{id}")public Result id(@PathVariable String id) {  //url传值UserDto userDto = userService.id(id);return Result.ok().put("data", userDto);}@PostMapping("/add")public Result add(@RequestBody UserDto user) { //对象传值UserDto userDto = userService.add(user);return Result.ok().put("data", userDto);}
}

 5.修改第一个项目hystrix1的application.yml文件

向其中添加以下代码

feign:hystrix:enabled: true

6.先同时启动两个项目,在postman进行测试 

3.6.1连接成功的情况

3.6.2连接失败的情况(提示) 

四.添加仪表盘(很少用到,了解)

1.在第一个工程里hystrix1添加依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

 2.添加配置类(固定写法)

package com.jr.config;import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.servlet.http.HttpServlet;@Configuration
public class HystrixConfig {@Beanpublic ServletRegistrationBean<HttpServlet> httpServletServletRegistrationBean() {ServletRegistrationBean<HttpServlet> result = new ServletRegistrationBean<>(new HystrixMetricsStreamServlet());result.addUrlMappings("/actuator/hystrix.stream");return result;}}

3.启动类添加注解@EnableHystrixDashboard

4启动项目,访问如下地址

地址栏访问的地址:http://localhost:100/hystrix

地址2:http://localhost:100/actuator/hystrix.stream

点击下面的Monitor Stream

 一开始建立的时候全是0,我们需要去访问我们的项目

 五.我的项目结构

1.第一个工程hystrix1

2.第一个工程hystrix2

http://www.yayakq.cn/news/938521/

相关文章:

  • 绿色在线网站模板下载广西桂林旅游几月份去最好
  • 企业为什么建立企业网站潘家园网站建设
  • 创建网站平台贵州飞乐云毕节网站建设
  • 威海外贸网站建设怎么样包装设计网站官网
  • 圣辉友联网站建设模仿网站侵权吗
  • 怎样打造营销型网站建设松江微网站建设
  • 大形电商网站开发费用网站备案文件吗
  • 网站域名备案变更建站哪家好联系兴田德润
  • 电子商务网站开发实训总结呼和浩特市网站公司
  • 网站 站外链接吉安网站
  • 网站建设 镇江杭州网站建设faxide
  • 公司网站推广的方法定制网站制作费用
  • 广州兼职网网站建设洛阳设计公司官网
  • 罗湖住房和建设局网站官网外贸平台有哪些?
  • 电子商务网站开发的视频网站建设免费按词收费
  • 为什么做的网站搜不出来福州网站建设平台
  • 做gif动图的素材网站宁波seo关键词优化教程
  • 二道网站建设南京哪家网络公司做网站优化好
  • 连连建设跨境电商网站WordPress多站点同步设置
  • 商务网站底部设计深圳网络技术有限公司
  • dede的网站地图百度关键词价格
  • wordpress 所有过滤器整站优化seo平台
  • 山西网络公司网站建设给企业做网站用什么程序
  • 做游乐设施模型的网站图门市建设局网站
  • 网站建设行内资讯上海公司注册网
  • 网站是否开启gzipwordpress 评论 插件
  • 如何提升网站权重模版网站可以做seo吗
  • 杭州网站设计首选柚米建设工程其它费计算网站
  • 自己做动漫头像的网站app程序开发制作公司
  • 福州网站建设机构wordpress数据分析