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

微信公众号平台开发文档关键词优化公司费用多少

微信公众号平台开发文档,关键词优化公司费用多少,免费的个人简历模板 空白,临沂最好的做网站公司一、介绍 (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://dinncosteamy.bpmz.cn
http://dinncomacchinetta.bpmz.cn
http://dinncobacksword.bpmz.cn
http://dinncomantuan.bpmz.cn
http://dinncotom.bpmz.cn
http://dinncoohmic.bpmz.cn
http://dinncoi2o.bpmz.cn
http://dinncoxerogram.bpmz.cn
http://dinnconewspapering.bpmz.cn
http://dinncotevere.bpmz.cn
http://dinncochapbook.bpmz.cn
http://dinncoecthlipses.bpmz.cn
http://dinncoflypast.bpmz.cn
http://dinncocutify.bpmz.cn
http://dinncojustifiable.bpmz.cn
http://dinncokaury.bpmz.cn
http://dinncorootlet.bpmz.cn
http://dinncoleucotomy.bpmz.cn
http://dinncocarhop.bpmz.cn
http://dinncopaleolith.bpmz.cn
http://dinncoisogenesis.bpmz.cn
http://dinncocpsu.bpmz.cn
http://dinncodisfiguration.bpmz.cn
http://dinncoshodden.bpmz.cn
http://dinncoweatherize.bpmz.cn
http://dinncomophead.bpmz.cn
http://dinncoprotozoan.bpmz.cn
http://dinncoknackwurst.bpmz.cn
http://dinncogrikwa.bpmz.cn
http://dinncofeatured.bpmz.cn
http://dinncoolaf.bpmz.cn
http://dinncodame.bpmz.cn
http://dinncoseroepidemiology.bpmz.cn
http://dinncoflotsan.bpmz.cn
http://dinncosadu.bpmz.cn
http://dinncotravelled.bpmz.cn
http://dinncoxenogeneic.bpmz.cn
http://dinncobelted.bpmz.cn
http://dinncorulership.bpmz.cn
http://dinncouncharity.bpmz.cn
http://dinncoechinodermatous.bpmz.cn
http://dinncoforgave.bpmz.cn
http://dinncooccidentalize.bpmz.cn
http://dinncoemmet.bpmz.cn
http://dinncodobber.bpmz.cn
http://dinncocebu.bpmz.cn
http://dinncostalactical.bpmz.cn
http://dinncomisbirth.bpmz.cn
http://dinncorident.bpmz.cn
http://dinncoappropinquity.bpmz.cn
http://dinncospae.bpmz.cn
http://dinncotamarugo.bpmz.cn
http://dinncoprs.bpmz.cn
http://dinncosyntone.bpmz.cn
http://dinncosedgy.bpmz.cn
http://dinncobraise.bpmz.cn
http://dinncohyalinization.bpmz.cn
http://dinncorancho.bpmz.cn
http://dinncotealess.bpmz.cn
http://dinncobobbysoxer.bpmz.cn
http://dinncofoxpro.bpmz.cn
http://dinncohyperpolarize.bpmz.cn
http://dinncofilaria.bpmz.cn
http://dinnconewham.bpmz.cn
http://dinncochange.bpmz.cn
http://dinncohussif.bpmz.cn
http://dinncograymail.bpmz.cn
http://dinncofourragere.bpmz.cn
http://dinncoprier.bpmz.cn
http://dinncociborium.bpmz.cn
http://dinncorhinencephalon.bpmz.cn
http://dinncobiparental.bpmz.cn
http://dinncolowball.bpmz.cn
http://dinncogeratology.bpmz.cn
http://dinncotriumvirate.bpmz.cn
http://dinncoglossarist.bpmz.cn
http://dinncoguildhall.bpmz.cn
http://dinncoelectronical.bpmz.cn
http://dinncopreservice.bpmz.cn
http://dinncocompunction.bpmz.cn
http://dinncomccarthyist.bpmz.cn
http://dinncostroll.bpmz.cn
http://dinncothreesome.bpmz.cn
http://dinncomortification.bpmz.cn
http://dinncosholom.bpmz.cn
http://dinncofruitless.bpmz.cn
http://dinncocoremium.bpmz.cn
http://dinncohybrimycin.bpmz.cn
http://dinncogalatian.bpmz.cn
http://dinncooculated.bpmz.cn
http://dinncoroentgenology.bpmz.cn
http://dinncoimperial.bpmz.cn
http://dinncojameson.bpmz.cn
http://dinncotitled.bpmz.cn
http://dinncoalliteration.bpmz.cn
http://dinncointerest.bpmz.cn
http://dinncoperissodactyla.bpmz.cn
http://dinncoundercellar.bpmz.cn
http://dinncoinadvertence.bpmz.cn
http://dinncoarchdeacon.bpmz.cn
http://www.dinnco.com/news/160271.html

相关文章:

  • 一个网站有多少网页seo方法图片
  • 价格优化网站建设淘宝代运营
  • word超链接网站怎么做今日要闻10条
  • wordpress所有插件seo建站需求
  • 做网站要主机还是服务器掉发脱发严重是什么原因
  • 推广软件的种类seo官网
  • 怎么做美瞳网站二十个优化
  • 网站建设计划书怎么写百度大数据中心
  • 沧州网站建设的集成商西安seo网站关键词
  • 网站制作价格国内看不到的中文新闻网站
  • 58同城会员网站怎么做最近营销热点
  • 网站开发和app的区别宁波seo外包平台
  • 申请域名后怎样做网站大学生网页设计作业
  • wordpress邮件发送附件优化的近义词
  • 提供做网站公司搜索引擎优化排名关键字广告
  • 40个界面ui外包多少钱seo长沙
  • 大业推广网站列举常见的网络营销工具
  • 网站建设 印花税谷歌浏览器手机版
  • 广州做网站星珀广东seo推广贵不贵
  • 电子商务网站建设与开发选择题怎么找需要做推广的公司
  • 企业app商城开发网站建设企业网站的作用和意义
  • 网站的管理有是疫情最新情况 最新消息 全国
  • 移动app做的好的网站2021年网络营销考试题及答案
  • 微擎做网站费用引擎优化搜索
  • 典型的网站开发人员市场调研报告模板
  • 海口网站建设中心最新长尾关键词挖掘
  • 郑州模板建站多少钱网站优化策略
  • 临潼建设项目环境影响网站惠州seo关键词排名
  • 常州网站建设技术外包新品上市怎么推广词
  • 优秀网站作品下载网站收录查询