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

psd wordpressshopify seo

psd wordpress,shopify seo,浙江网站建设上市公司,wdcp备份的数据库网站文件在哪里一、介绍 (1)避免单个服务出现故障导致整个应用崩溃。 (2)服务降级:服务超时、服务异常、服务宕机时,执行定义好的方法。(做别的) (3)服务熔断:达…

一、介绍

(1)避免单个服务出现故障导致整个应用崩溃。
(2)服务降级:服务超时、服务异常、服务宕机时,执行定义好的方法。(做别的)
(3)服务熔断:达到熔断条件时,服务禁止被访问,执行定义好的方法。(不做了)
(4)服务限流:高并发场景下的一大波流量过来时,让其排队访问。(排队做)

二、构建项目

(1)pom.xml

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>com.wsh.springcloud</groupId><artifactId>cloud-api-common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>

(2)编写application.yml文件

server:port: 8001spring:application:name: cloud-provider-hystrix-paymentdatasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: org.gjt.mm.mysql.Driverurl: jdbc:mysql://localhost:3306/springcloud?useUnicode=true&characterEncoding=utf-8&useSSL=falseusername: rootpassword: wsh666eureka:client:register-with-eureka: truefetch-registry: trueservice-url:defaultZone: http://eureka1.com:7001/eurekainstance:instance-id: hystrixPayment8001prefer-ip-address: true

(3)启动类PaymentHystrixMain8001

package com.wsh.springcloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;/*** @ClassName PaymentHystrixMain8001* @Description: TODO* @Author wshaha* @Date 2023/10/14* @Version V1.0**/
@SpringBootApplication
@EnableEurekaClient
public class PaymentHystrixMain8001 {public static void main(String[] args) {SpringApplication.run(PaymentHystrixMain8001.class, args);}
}

(4)编写PaymentService

package com.wsh.springcloud.service;import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;/*** @ClassName PaymentService* @Description: TODO* @Author wshaha* @Date 2023/10/14* @Version V1.0**/
@Service
@Slf4j
public class PaymentService {public String test1(Integer id){return "test1: " + Thread.currentThread().getName() + " " + id;}public String test2(Integer id){try {Thread.sleep(3000);} catch (Exception e){}return "test2: " + Thread.currentThread().getName() + " " + id;}
}

(5)编写PaymentController

package com.wsh.springcloud.controller;import com.wsh.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
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;/*** @ClassName PaymentController* @Description: TODO* @Author wshaha* @Date 2023/10/14* @Version V1.0**/
@Slf4j
@RequestMapping("/payment")
@RestController
public class PaymentController {@Autowiredprivate PaymentService paymentService;@GetMapping("/test1/{id}")public String test1(@PathVariable("id") Integer id){return paymentService.test1(id);}@GetMapping("/test2/{id}")public String test2(@PathVariable("id") Integer id){return paymentService.test2(id);}
}

(6)运行
在这里插入图片描述

三、 服务降级配置

(1)方式一(一旦方法出现异常或超时了,会调用@HystrixCommand的降级方法)

注:@EnableCircuitBreaker用于启动断路器,支持多种断路器,@EnableHystrix用于启动断路器,只支持Hystrix断路器

a、PaymentService编写降级方法,配置注解@HystrixCommand

@Service
@Slf4j
public class PaymentService {public String test1(Integer id){return "test1: " + Thread.currentThread().getName() + " " + id;}@HystrixCommand(fallbackMethod = "test2fallback", commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})public String test2(Integer id){try {Thread.sleep(3000);} catch (Exception e){}return "test2: " + Thread.currentThread().getName() + " " + id;}public String test2fallback(Integer id){return "test2fallback: " + id;}
}

b、启动类开启断路器

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class PaymentHystrixMain8001 {public static void main(String[] args) {SpringApplication.run(PaymentHystrixMain8001.class, args);}
}

c、运行
在这里插入图片描述
(2)方式二(配置全局使用的降级方法)
a、使用@DefaultProperties,注意全局降级方法的参数列表为空

@Slf4j
@RequestMapping("/payment")
@RestController
@DefaultProperties(defaultFallback = "defaultFallbacktest")
public class PaymentController {@Autowiredprivate PaymentService paymentService;@GetMapping("/test1/{id}")public String test1(@PathVariable("id") Integer id){return paymentService.test1(id);}@GetMapping("/test2/{id}")@HystrixCommandpublic String test2(@PathVariable("id") Integer id){return paymentService.test2(id);}public String defaultFallbacktest(){return "defaultFallbacktest";}
}

b、编写PaymentService

@Service
@Slf4j
public class PaymentService {public String test1(Integer id){return "test1: " + Thread.currentThread().getName() + " " + id;}//    @HystrixCommand(fallbackMethod = "test2fallback", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
//    })public String test2(Integer id){
//        try {
//            Thread.sleep(3000);
//        } catch (Exception e){
//
//        }int i = 1 / 0;return "test2: " + Thread.currentThread().getName() + " " + id;}
//    public String test2fallback(Integer id){
//        return "test2fallback: " + id;
//    }
}

c、运行
在这里插入图片描述
(3)方式三,feign调用其他服务时,可以利用实现类对应降级方法
a、pom.xml增加依赖

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

b、application.yml增加

feign:hystrix:enabled: true

c、编写远程调用接口FeignTestService

@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE", fallback = FeignTestServiceImpl.class)
public interface FeignTestService {@GetMapping("/payment/test")public CommonResult<String> test();
}

d、编写降级方法类FeignTestServiceImpl

@Component
public class FeignTestServiceImpl implements FeignTestService{@Overridepublic CommonResult<String> test() {return new CommonResult(444, "", "error");}
}

e、编写Controller

@Slf4j
@RequestMapping("/payment")
@RestController
//@DefaultProperties(defaultFallback = "defaultFallbacktest")
public class PaymentController {@Autowiredprivate PaymentService paymentService;@Autowiredprivate FeignTestService feignTestService;@GetMapping("/test1/{id}")public String test1(@PathVariable("id") Integer id){return paymentService.test1(id);}@GetMapping("/test2/{id}")
//    @HystrixCommandpublic String test2(@PathVariable("id") Integer id){return paymentService.test2(id);}
//    public String defaultFallbacktest(){
//        return "defaultFallbacktest";
//    }@GetMapping("/test")public CommonResult<String> test(){return feignTestService.test();}
}

f、运行
在这里插入图片描述

四、服务熔断配置

(1)服务先降级,然后熔断,后面尝试恢复
(2)在规定时间内,接口访问量超过设置阈值,并且失败率大于等于设置阈值
(3)例子

@Service
@Slf4j
public class PaymentService {@HystrixCommand(fallbackMethod = "test1fallback", commandProperties = {@HystrixProperty(name = "circuitBreaker.enabled", value = "true"),//开启断路器@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),//请求次数阈值@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),//规定时间内@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60")//失败率阈值})public String test1(Integer id){int i = 1 / id;return "test1: " + Thread.currentThread().getName() + " " + id;}public String test1fallback(Integer id){return "test1fallback: " + id;}//    @HystrixCommand(fallbackMethod = "test2fallback", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
//    })public String test2(Integer id){
//        try {
//            Thread.sleep(3000);
//        } catch (Exception e){
//
//        }int i = 1 / 0;return "test2: " + Thread.currentThread().getName() + " " + id;}
//    public String test2fallback(Integer id){
//        return "test2fallback: " + id;
//    }
}

五、监控界面搭建(只能监控hystrix接管的方法)

(1)编写pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>demo20220821</artifactId><groupId>com.wsh.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-consumer-hystrix-dashboard9001</artifactId><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></dependency><dependency><groupId>com.wsh.springcloud</groupId><artifactId>cloud-api-common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-actuator</artifactId>-->
<!--        </dependency>--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
</project>

(2)编写application.yml

server:port: 9001spring:application:name: cloud-hystrix-dashboard

(3)编写启动类

package com.wsh.springcloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;/*** @ClassName HystrixDashboardMain9001* @Description: TODO* @Author wshaha* @Date 2023/10/14* @Version V1.0**/
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardMain9001 {public static void main(String[] args) {SpringApplication.run(HystrixDashboardMain9001.class, args);}
}

(4)运行
在这里插入图片描述
(5)配置被监控的项目
a、pom.xml

加上探针spring-boot-starter-actuator

b、启动类加上

package com.wsh.springcloud;import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;/*** @ClassName PaymentHystrixMain8001* @Description: TODO* @Author wshaha* @Date 2023/10/14* @Version V1.0**/
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
@EnableFeignClients
public class PaymentHystrixMain8001 {public static void main(String[] args) {SpringApplication.run(PaymentHystrixMain8001.class, args);}@Beanpublic ServletRegistrationBean getServlet(){HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(hystrixMetricsStreamServlet);servletRegistrationBean.setLoadOnStartup(1);servletRegistrationBean.addUrlMappings("/hystrix.stream");servletRegistrationBean.setName("HystrixMetricsStreamServlet");return servletRegistrationBean;}
}

(6)监控界面
在这里插入图片描述
在这里插入图片描述


文章转载自:
http://cottonmouth.fwrr.cn
http://pensione.fwrr.cn
http://glucoside.fwrr.cn
http://oct.fwrr.cn
http://lapel.fwrr.cn
http://ergometric.fwrr.cn
http://rigor.fwrr.cn
http://bespread.fwrr.cn
http://edentate.fwrr.cn
http://taganrog.fwrr.cn
http://oklahoman.fwrr.cn
http://granicus.fwrr.cn
http://slotware.fwrr.cn
http://serenity.fwrr.cn
http://sham.fwrr.cn
http://brinell.fwrr.cn
http://firebug.fwrr.cn
http://mitigative.fwrr.cn
http://vulgarize.fwrr.cn
http://accra.fwrr.cn
http://psoas.fwrr.cn
http://ravelment.fwrr.cn
http://guarded.fwrr.cn
http://backstage.fwrr.cn
http://gallophil.fwrr.cn
http://volatilization.fwrr.cn
http://coir.fwrr.cn
http://hypergeusesthesia.fwrr.cn
http://nadir.fwrr.cn
http://always.fwrr.cn
http://inkiyo.fwrr.cn
http://disinvite.fwrr.cn
http://camoufleur.fwrr.cn
http://perithelium.fwrr.cn
http://apparently.fwrr.cn
http://parasang.fwrr.cn
http://gooral.fwrr.cn
http://intolerably.fwrr.cn
http://anodontia.fwrr.cn
http://anion.fwrr.cn
http://heteroplasia.fwrr.cn
http://taeniasis.fwrr.cn
http://principial.fwrr.cn
http://slut.fwrr.cn
http://homogamous.fwrr.cn
http://pickax.fwrr.cn
http://configuration.fwrr.cn
http://violist.fwrr.cn
http://shadchan.fwrr.cn
http://micropore.fwrr.cn
http://cluw.fwrr.cn
http://brogue.fwrr.cn
http://jigotai.fwrr.cn
http://papyrograph.fwrr.cn
http://pestiferous.fwrr.cn
http://handbag.fwrr.cn
http://cordillera.fwrr.cn
http://kinetosome.fwrr.cn
http://linkboy.fwrr.cn
http://casque.fwrr.cn
http://knickered.fwrr.cn
http://lectionary.fwrr.cn
http://col.fwrr.cn
http://tele.fwrr.cn
http://labor.fwrr.cn
http://runological.fwrr.cn
http://cassation.fwrr.cn
http://somewhere.fwrr.cn
http://locksmithing.fwrr.cn
http://cupric.fwrr.cn
http://intersterile.fwrr.cn
http://metope.fwrr.cn
http://repugnancy.fwrr.cn
http://megakaryocyte.fwrr.cn
http://outpensioner.fwrr.cn
http://shylock.fwrr.cn
http://rigorousness.fwrr.cn
http://nastiness.fwrr.cn
http://pencil.fwrr.cn
http://formularization.fwrr.cn
http://allegation.fwrr.cn
http://decasyllabic.fwrr.cn
http://bigamy.fwrr.cn
http://rhymeless.fwrr.cn
http://curiousness.fwrr.cn
http://espadrille.fwrr.cn
http://garbageology.fwrr.cn
http://monochrome.fwrr.cn
http://thinking.fwrr.cn
http://coatdress.fwrr.cn
http://garnet.fwrr.cn
http://oxidoreductase.fwrr.cn
http://flexure.fwrr.cn
http://hanging.fwrr.cn
http://granicus.fwrr.cn
http://nixonian.fwrr.cn
http://adverse.fwrr.cn
http://runnerless.fwrr.cn
http://teleconferencing.fwrr.cn
http://interventionism.fwrr.cn
http://www.dt0577.cn/news/70848.html

相关文章:

  • 协会类网站免费模板seo实战技巧100例
  • 专业的广州微网站建设2022知名品牌营销案例100例
  • 莆田哪里有学做网站的2024百度下载
  • 网站建设的评价成都百度
  • 外贸网站示例南京怎样优化关键词排名
  • html5农业网站模板免费测试seo
  • 网站服务器权限代运营公司怎么找客户
  • wordpress 开发h5页面seo推广培训中心
  • 网站结构怎么做适合优化嵌入式培训机构哪家好
  • 哪家网站建设公司世界足球排名前十名
  • 图书馆网站建设建议百度推广开户价格
  • 网站程序流程图内容营销成功案例
  • 专业团队为您服务seo站内优化和站外优化
  • 电脑在哪网站接做扇子单百度推广账号注册流程
  • vue配合什么做网站比较好网站seo分析报告
  • 公众号采集wordpress网站关键词优化办法
  • 官方百度网站优化排名哪家性价比高
  • 肇庆做网站的有推广公司有哪些
  • 软件下载的网站梁水才seo优化专家
  • 视频网站调用常宁seo外包
  • 网站可以做的线下活动百度统计app
  • 369网站建设中心搜索引擎优化的报告
  • 做网站开发的需求文档b站推广引流最佳方法
  • 美食网站模版百度视频
  • 产品展示网站 模板优化师是做什么的
  • 国家企业信用网官网长沙网站seo公司
  • 厦门入夏网站建设公司青岛网站建设公司电话
  • 政府门户网站建设的误区网站建设需要啥
  • 津南网站建设百度统计工具
  • 杭州网站建设公司有哪些seo网站编辑是做什么的