SpringCloud+SpringCloudAlibaba學(xué)習(xí)筆記

SpringCloud

服務(wù)注冊中心

eureka

ap 高可用 分布式容錯

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
eureka:
  instance:
    hostname: eureka7003.com #eureka服務(wù)端的實(shí)例名稱
    instance-id: payment8001 
    prefer-ip-address: true
  client:
    register-with-eureka: false     #false表示不向注冊中心注冊自己郭变。
    fetch-registry: false     #false表示自己端就是注冊中心,我的職責(zé)就是維護(hù)服務(wù)實(shí)例州叠,并不需要去檢索服務(wù)
    service-url:
      #集群指向其它eureka
      #defaultZone: http://eureka7002.com:7002/eureka/
      #單機(jī)就是7001自己
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
    #server:
    #關(guān)閉自我保護(hù)機(jī)制印屁,保證不可用服務(wù)被及時(shí)踢除
    #enable-self-preservation: false
    #eviction-interval-timer-in-ms: 2000

Ribbon 啟用負(fù)載均衡

@EnableEurekaServer
@EnableDiscoveryClient

@LoadBalanced
public RestTemplate getTemp() {
    return new RestTemplate();
}

zookepper

cp 強(qiáng)一致 分布式容錯

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>3.6.1</version>
</dependency>
spring:
  application:
    name: cloud-zoo-consumer-order
  cloud:
    zookeeper:
      connect-string: 192.168.10.58:2181

@SpringBootApplication
@EnableDiscoveryClient

consul

cp 強(qiáng)一致 分布式容錯

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
spring:
  application:
    name: consul-payment-provider
  cloud:
    consul:
      host: 192.168.10.58
      port: 8500
      discovery:
        service-name: ${spring.application.name}
@SpringBootApplication
@EnableDiscoveryClient

服務(wù)調(diào)用負(fù)載均衡

Ribbon

Ribbon 切換 負(fù)載規(guī)則

  1. 在springboot 包掃描外層建立 配置
@Configuration
public class Myrule {
    @Bean
    public IRule initRule() {
        return new RandomRule();
    }
}
  1. 啟動類給指定服務(wù)加載隨機(jī)方法
@RibbonClient(name = "CLOUD-PAYMENT-SERVICE", configuration = Myrule.class)

OpenFeign

  1. 添加maven依賴
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
  1. 啟動類啟用Feign
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
  1. 新建接口 并注冊Feign信息
@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")  //提供方服務(wù)名
public interface Service {
    @GetMapping(value = "/payment/get/{id}")
    Response<Payment> getPaymentById(@PathVariable("id") Long id);
}
  1. 提供方接口演示
@GetMapping(value = "/payment/get/{id}")
public Response<Payment> getPaymentById(@PathVariable("id") Long id) {
    Payment payment = paymentService.getPaymentById(id);

    if (payment != null) {
        return Result.success(200, "查詢成功,serverPort:  " + serverPort, payment);
    } else {
        return Result.success(444, "沒有對應(yīng)記錄,查詢ID: " + id, null);
    }
}

OpenFeign超時(shí)設(shè)置

ribbon:
#指的是建立連接所用的時(shí)間,適用于網(wǎng)絡(luò)狀況正常的情況下,兩端連接所用的時(shí)間
  ReadTimeout: 5000
#指的是建立連接后從服務(wù)器讀取到可用資源所用的時(shí)間
  ConnectTimeout: 5000

OpenFeign 日志打印功能

  1. 配置Openfeign 日志級別
@Configuration
public class FeignLogConfig {
    @Bean
    public Logger.Level getLevel() {
        return Logger.Level.FULL;
    }
}
  1. yml 項(xiàng)目配置文件中,給指定Feign interface 配置日志級別
logging:
  level:
    ml.ytooo.feignservice.Service: debug

Hystrix 服務(wù)治理

  • 服務(wù)降級 出險(xiǎn)異常時(shí),返回友好提示,防止程序異常或者阻塞
  • 服務(wù)熔斷 保險(xiǎn)絲,當(dāng)超出服務(wù)承載能力時(shí),返回提示,拒絕請求
  • 服務(wù)限流 閘門,配置服務(wù)承載能力

Hystrix

服務(wù)降級
當(dāng)服務(wù)處理超時(shí)或者運(yùn)行異常時(shí),啟動備選方案返回給調(diào)用者預(yù)期結(jié)果

主方法

@EnableCircuitBreaker

需要降級處理的程序

其中

  • paymentInfo_TimeOut 為預(yù)計(jì)超時(shí)程序
  • paymentInfo_TimeOut_Handler 為超時(shí)備選方案
@HystrixCommand(fallbackMethod = "paymentInfo_TimeOut_Handler", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
})
public String paymentInfo_TimeOut(Integer id) {

    int time = 5;
    try { TimeUnit.MILLISECONDS.sleep(time * 1000); } catch (InterruptedException e) { e.printStackTrace(); }
    return "線程池:  " + Thread.currentThread().getName() + " paymentInfo_TimeOut,id:  " + id + "\t" + "O(∩_∩)O哈哈~" + "  耗時(shí)(秒): " + time;
}

public String paymentInfo_TimeOut_Handler(Integer id) {
    return "線程池:  " + Thread.currentThread().getName() + " paymentInfo_TimeOut_Handler,id:  " + id + "\t" + "o(╥﹏╥)o";
}
全局降級處理

配置 defaultFallback 的走自己的降級方法,未配置的走 默認(rèn)@DefaultProperties 指定的降級方法

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "globle",commandProperties = {
        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
})
public class Controller {
    @HystrixCommand
    @GetMapping("/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id) {
        String result = feignService.paymentInfo_TimeOut(id);
        log.info("*****result: " + result);
        return result;
    }
    public String globle() {
        return "全局";
    }
}
通過OpenFeign 配置其提供方全局降級配置
  1. 新增feign調(diào)用接口的實(shí)現(xiàn)類 FeignServiceImpl,實(shí)現(xiàn)全部方法并做降級處理
@Service
public class FeignServiceImpl implements FeignService {
    @Override
    public String paymentInfo_OK(Integer id) {
        return "降級 -- paymentInfo_OK";
    }
    @Override
    public String paymentInfo_TimeOut(Integer id) {
        return "降級 -- paymentInfo_TimeOut";
    }
}
  1. feign調(diào)用接口添加注解
@FeignClient(value = "CLOUD-PROVIDER-HYSTYRIX-PAYMENT",fallback = FeignServiceImpl.class)
服務(wù)熔斷
  • 服務(wù)過載時(shí),拒絕連接請求直接調(diào)用降級方法,返回異常
  • 請求下降時(shí),慢慢恢復(fù)該服務(wù)訪問,直達(dá)完全恢復(fù)

配置服務(wù)的熔斷:

一下配置在 10s 內(nèi) ,10次請求有60% 失敗,則熔斷

HystrixProperty 配置位于 HystrixCommandProperties.class 類中

//=====服務(wù)熔斷
@HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",commandProperties = { //
        @HystrixProperty(name = "circuitBreaker.enabled",value = "true"),// 是否開啟斷路器
        @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",value = "10"),// 請求次數(shù)
        @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",value = "10000"), // 時(shí)間窗口期
        @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage",value = "60"),// 失敗率達(dá)到多少百分百后跳閘
})
public String paymentCircuitBreaker(@PathVariable("id") Integer id)
{
    if(id < 0)
    {
        throw new RuntimeException("******id 不能負(fù)數(shù)");
    }
    String serialNumber = IdUtil.simpleUUID();

    return Thread.currentThread().getName()+"\t"+"調(diào)用成功吼具,流水號: " + serialNumber;
}
public String paymentCircuitBreaker_fallback(@PathVariable("id") Integer id) //熔斷后降級方法
{
    return "id 不能負(fù)數(shù)僚纷,請稍后再試,/(ㄒoㄒ)/~~   id: " +id;
}

效果: 當(dāng)連續(xù)使用 -100 請求時(shí), 返回 "id 不能負(fù)數(shù)", 使用100請求也返回 "id 不能負(fù)數(shù)" ,繼續(xù)連續(xù)使用 100請求, 服務(wù)慢慢恢復(fù)

服務(wù)限流

使用 springcloud 阿里巴巴 sentinel 替代

Gateway 網(wǎng)關(guān)

Gateway

Gateway 項(xiàng)目配置

  1. 添加maven依賴
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
  1. 移除以下依賴
<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>
  1. yml 配置 (后續(xù)移步配置中心)
spring:
  application:
    name: cloud-gateaway-gateaway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
      routes:
        - id: payment_get
        #   uri: http://127.0.0.1:8001    #單一節(jié)點(diǎn)
          uri : lb://CLOUD-PAYMENT-SERVICE  /#啟用 注冊中心集群
          predicates:
            - Path=/payment/get/**
  1. 注冊進(jìn) Eureka 注冊中心

Gateway 動態(tài)路由

  1. 開啟 網(wǎng)關(guān)發(fā)現(xiàn)注冊中心服務(wù)
spring:
  application:
    name: cloud-gateaway-gateaway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true

Gateway 斷言

斷言是判斷轉(zhuǎn)發(fā)請求的條件

predicates:
 - After=2020-02-21T15:51:37.485+08:00[Asia/Shanghai]
  1. After,Before,Between 配置轉(zhuǎn)發(fā)生效時(shí)間
public static void main(String[] args) {
    ZonedDateTime now = ZonedDateTime.now();
    System.out.println(now);
}
// 2020-08-24T14:23:57.171+08:00[Asia/Shanghai]
  1. Cookie 請求需攜帶指定Cookie才可以訪問
predicates:
  - Cookie=name,ytooo   # key,value
  1. Header ≈ Cookie
predicates:
  - Header=name,ytooo   # key,value

Gateway 過濾器

  1. (默認(rèn)過濾器) 官方提供一系列過濾器,供我們 在請求轉(zhuǎn)發(fā)之前,對請求進(jìn)行加工處理
filters:
  - AddRequestParamter=rowid,1024
  1. 自定義過濾器

自定義全局過濾器

@Component
@Slf4j
public class GatewayLogFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("=====================進(jìn)入全局過濾器=====================");
        String name = exchange.getRequest().getQueryParams().getFirst("name");
        if (null == name) {
            exchange.getResponse().setStatusCode(HttpStatus.FORBIDDEN);
            return exchange.getResponse().setComplete();
        }
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}

SpringCloud Config 分布式配置中心, BUS 消息總線

分布式配置中心 SpringCloud Config

服務(wù)端配置

  1. 建立git倉庫 https://github.com/youdmeng/cloud-config

  2. 引入 maven

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>

3.啟動類使配置生效

@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class ConfigMain3344 {
    public static void main(String[] args) {
        SpringApplication.run(ConfigMain3344.class, args);
    }
}
  1. 配置 配置文件
spring:
  application:
    name: cloud-config-center
  cloud:
    config:
      server:
        git:
          uri: https://github.com/youdmeng/cloud-config
          search-paths:
            - cloud-config
      label: master
  1. 請求訪問 : http://127.0.0.1:3344/master/config-dev.yml

客戶端配置

  1. 引入 maven
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-client</artifactId>
</dependency>
  1. 配置 配置文件
spring:
  application:
    name: cloud-condig-client
  cloud:
    config:
      label: master  # 分支
      name: config # 配置文件名稱
      profile: dev   # 版本
      uri: http://127.0.0.1:3344 # config服務(wù)端地址

手動刷新客戶端配置

不建議使用

消息總線 Bus

設(shè)計(jì)邏輯

使用消息總線觸發(fā)服務(wù)端的 bus/refresh 端點(diǎn),刷新所有客戶端config配置

初始條件

客戶端,服務(wù)端都需要實(shí)現(xiàn)Springcloud Config功能

服務(wù)端配置

  1. 引入maven依賴
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
  1. 配置文件中配置消息隊(duì)列信息
# 配置消息隊(duì)列
rabbitmq:
  host: 192.168.10.58
  port: 5672
  username: ytooo
  password: ytooo
  1. 配置文件中配置BUS總線暴露信息
# 配置bus暴露端點(diǎn)
management:
  endpoints:
    web:
      exposure:
        include: "bus-refresh"
  1. 配置文件預(yù)覽
server:
  port: 3344
spring:
  application:
    name: cloud-config-center
  cloud:
    config:
      server:
        git:
          uri: https://github.com/youdmeng/cloud-config
          search-paths:
            - cloud-config
      label: master
  # 配置消息隊(duì)列
  rabbitmq:
    host: 192.168.10.58
    port: 5672
    username: ytooo
    password: ytooo
eureka:
  instance:
    prefer-ip-address: true
    instance-id: cloud-config-center-3344
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/ #,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
# 配置bus暴露端點(diǎn)
management:
  endpoints:
    web:
      exposure:
        include: "bus-refresh"

客戶端配置

  1. 引入maven依賴
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
  1. 配置文件中配置消息隊(duì)列信息
# 配置消息隊(duì)列
rabbitmq:
  host: 192.168.10.58
  port: 5672
  username: ytooo
  password: ytooo
  1. 配置暴露端點(diǎn)
# 配置暴露端點(diǎn)
management:
  endpoints:
    web:
      exposure:
        include: "*"
  1. 調(diào)用配置類添加 @RefreshScope

@RestController
@RefreshScope
public class Controller {
    @Value("${config.info}")
    private String configInfo;
    @GetMapping(value = "/test")
    public String test() {
        return configInfo;
    }
}

刷新配置

POST 請求config服務(wù)端 http://127.0.0.1:3344/actuator/bus-refresh

刷新成功

定點(diǎn)通知

POST 請求config服務(wù)端 http://127.0.0.1:3344/actuator/bus-refresh/{destination}

destination: 注冊中心服務(wù)名稱:端口號

??: http://127.0.0.1:3344/actuator/bus-refresh/cloud-condig-client:3366

SpringCloud Stream 消息驅(qū)動

消息驅(qū)動,統(tǒng)一各種消息中間件中的差異,提供統(tǒng)一簡單的調(diào)用方式,屏蔽消息中間件具體調(diào)用實(shí)現(xiàn)

SpringCloud Stream 消息提供者項(xiàng)目配置 (簡單使用)

  1. 添加maven依賴
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
  1. 配置文件添加Stream配置
spring:
  application:
    name: cloud-stream-provider
  cloud:
    stream:
      binders: # 在此處配置要綁定的rabbitmq的服務(wù)信息拗盒;
        defaultRabbit: # 表示定義的名稱怖竭,用于于binding整合
          type: rabbit # 消息組件類型
          environment: # 設(shè)置rabbitmq的相關(guān)的環(huán)境配置
            spring:
              rabbitmq:
                host: 192.168.10.58
                port: 5672
                username: ytooo
                password: ytooo
      bindings: # 服務(wù)的整合處理
        output: # 這個(gè)名字是一個(gè)通道的名稱
          destination: studyExchange # 表示要使用的Exchange名稱定義
          content-type: application/json # 設(shè)置消息類型,本次為json陡蝇,文本則設(shè)置“text/plain”
          binder: defaultRabbit # 設(shè)置要綁定的消息服務(wù)的具體設(shè)置
  1. 定義消息推送管道
@EnableBinding(Source.class) //定義消息推送管道
public class MsgProviderImpl implements MsgProvider {
}
  1. 定義消息發(fā)送管道
@Autowired
private MessageChannel out; //定義消息發(fā)送管道
  1. build消息實(shí)體并發(fā)送
Message<String> message = MessageBuilder.withPayload(msg).build();
out.send(message);
  1. 消息接收方 yml 配置
spring:
  application:
    name: cloud-stream-rabbitmq-consumer
  cloud:
    stream:
      binders: # 在此處配置要綁定的rabbitmq的服務(wù)信息痊臭;
        defaultRabbit: # 表示定義的名稱,用于于binding整合
          type: rabbit # 消息組件類型
          environment: # 設(shè)置rabbitmq的相關(guān)的環(huán)境配置
            spring:
              rabbitmq:
                host: 192.168.10.58
                port: 5672
                username: ytooo
                password: ytooo
      bindings: # 服務(wù)的整合處理
        input: # 這個(gè)名字是一個(gè)通道的名稱                                   
          destination: studyExchange # 表示要使用的Exchange名稱定義       需與提供方相同
          content-type: application/json # 設(shè)置消息類型登夫,本次為json广匙,文本則設(shè)置“text/plain”
          binder: defaultRabbit # 設(shè)置要綁定的消息服務(wù)的具體設(shè)置
  1. 接收方監(jiān)聽接口配置
@EnableBinding(Sink.class)
public class ReceiveMsgImpl implements ReceiveMsg {
}
  1. 接收方注解
@StreamListener(Sink.INPUT)
public void receive(Message<String> message) {
    System.out.println("客服端8803收到消息: " + message.getPayload());
}

SpringCloud Stream 分組消費(fèi) & 持久化

  • 對于不同的組中,消息是會被重復(fù)消費(fèi)的(重復(fù)消費(fèi))
  • 同一個(gè)組內(nèi),服務(wù)之間存在競爭關(guān)系,只被消費(fèi)一次(集群環(huán)境,避免重復(fù)消費(fèi))

分組配置文件配置

bindings: # 服務(wù)的整合處理
  input: # 這個(gè)名字是一個(gè)通道的名稱
    destination: studyExchange # 表示要使用的Exchange名稱定義
    content-type: application/json # 設(shè)置消息類型,本次為json恼策,文本則設(shè)置“text/plain”
    binder: defaultRabbit # 設(shè)置要綁定的消息服務(wù)的具體設(shè)置
    group: ytooo           #  配置接收方所在組

group分組 持久化

當(dāng)不配置分組時(shí),重啟服務(wù),不會自動獲取之前未消費(fèi)的服務(wù)
反之,配置了分組,啟動時(shí),自動獲取之前未消費(fèi)的消息

Sleuth 分布式請求鏈路跟蹤

我跳過了

SpringCloud Alibaba

Nacos 注冊中心

添加依賴

<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

項(xiàng)目配置文件

spring:
  application:
    name: cloudalibaba-nacos-consumer-order
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.10.58:8848

主程序啟動

@EnableDiscoveryClient

結(jié)合 Openfeign 調(diào)用 服務(wù)

Nacos config配置中心

  1. 添加maven 依賴
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-alibaba-nacos-config</artifactId>
</dependency>
  1. bootstrap.yml中添加 配置中心相關(guān)配置
spring:
  application:
    name: cloudalibaba-nacos-config-cclient
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.10.58:8848
      config:
        server-addr: 192.168.10.58:8848
        file-extension: yaml
  profiles:
    active: dev
  1. 業(yè)務(wù)類 添加 @RefreshScope 來自動刷新
@RestController
@RefreshScope
public class Controller {
  1. 配置文件中配置格式

在 Nacos Spring Cloud 中鸦致,dataId 的完整格式如下:

{prefix}-{spring.profiles.active}.${file-extension}

  • prefix 默認(rèn)為 spring.application.name 的值,也可以通過配置項(xiàng) spring.cloud.nacos.config.prefix來配置涣楷。
  • spring.profiles.active 即為當(dāng)前環(huán)境對應(yīng)的 profile分唾,詳情可以參考 Spring Boot文檔。 注意:當(dāng) spring.profiles.active 為空時(shí)狮斗,對應(yīng)的連接符 - 也將不存在绽乔,dataId 的拼接格式變成 {prefix}.{file-extension}
  • file-exetension 為配置內(nèi)容的數(shù)據(jù)格式,可以通過配置項(xiàng) spring.cloud.nacos.config.file-extension 來配置碳褒。目前只支持 properties 和 yaml 類型折砸。

本實(shí)例中文件名稱應(yīng)為: cloudalibaba-nacos-config-cclient-dev.yaml

Nacos config配置中心 分類配置

Nacos 使用3層來隔離服務(wù)

  • NameSpace 命名空間,默認(rèn) public
  • Group 組, 默認(rèn) DEFAULT_GROUP
  • Service 微服務(wù), 一個(gè)Service 可以包含多個(gè)Cluster集群,默認(rèn)Cluster為 DEFAULT 可以用了區(qū)分地域,來做地域容災(zāi)

yml 中配置分組信息group ,和命名空間 namespace

spring:
  application:
    name: cloudalibaba-nacos-config-cclient
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.10.58:8848
      config:
        server-addr: 192.168.10.58:8848
        file-extension: yaml
        group: dev
        namespace: a2438b02-01e1-4a3c-959c-600d93183d22 # 使用命名空間ID

Sentinel 服務(wù)熔斷與降級

  • 單獨(dú)的組件
  • 可以界面化,細(xì)粒度統(tǒng)一配置

Sentinel 服務(wù)被管方 配置

  1. maven 依賴
<dependency>
  <groupId>com.alibaba.csp</groupId>
  <artifactId>sentinel-datasource-nacos</artifactId>   <!-- Sentinel持久化 -->
</dependency>
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
  1. yml 中配置 sentinel dashboard 監(jiān)控
spring:
  application:
    name: cloudalibaba-sentinel-service
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.10.58:8848
    sentinel:
      transport:
        dashboard: 192.168.10.58:8888 # sentinel dashboard 地址

配置降級方法: 此方法只針對頁面中配置的指定 降級限流熱點(diǎn)等方法

@GetMapping(value = "/hot")
@SentinelResource(value = "hot", blockHandler = "deal_hot")
public String hot(String p1, String p2) {
    return "========================== 熱點(diǎn)通過 ==========================";
}

public String deal_hot(String p1, String p2, BlockException e) {
    return "========================== 熱點(diǎn)降級 ==========================";
}

seata 分布式事務(wù)

  • 全局事務(wù)id

  • TC 事務(wù)協(xié)調(diào)者 維護(hù)全局和分支事務(wù)狀態(tài),驅(qū)動全局事務(wù)的提交或回滾

  • TM 事務(wù)管理器 定義全局事務(wù)的范圍,開始全局事務(wù).提交或回滾全局事務(wù)

  • RM 資源管理器 管理分支事務(wù)處理的資源,與TC交談來注冊分支事務(wù)和報(bào)告分支事務(wù)的狀態(tài),并驅(qū)動分支事務(wù)的提交或回滾

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市沙峻,隨后出現(xiàn)的幾起案子睦授,更是在濱河造成了極大的恐慌,老刑警劉巖专酗,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件睹逃,死亡現(xiàn)場離奇詭異,居然都是意外死亡祷肯,警方通過查閱死者的電腦和手機(jī)沉填,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來佑笋,“玉大人翼闹,你說我怎么就攤上這事〗常” “怎么了猎荠?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵坚弱,是天一觀的道長。 經(jīng)常有香客問我关摇,道長荒叶,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任输虱,我火速辦了婚禮些楣,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘宪睹。我一直安慰自己愁茁,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布亭病。 她就那樣靜靜地躺著鹅很,像睡著了一般。 火紅的嫁衣襯著肌膚如雪罪帖。 梳的紋絲不亂的頭發(fā)上促煮,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天,我揣著相機(jī)與錄音胸蛛,去河邊找鬼污茵。 笑死樱报,一個(gè)胖子當(dāng)著我的面吹牛葬项,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播迹蛤,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了跪呈?” 一聲冷哼從身側(cè)響起圆裕,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎逆趣,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體宣渗,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年痕囱,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片鞍恢。...
    茶點(diǎn)故事閱讀 40,040評論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡每窖,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出弦悉,到底是詐尸還是另有隱情窒典,我是刑警寧澤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布稽莉,位于F島的核電站崇败,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏肩祥。R本人自食惡果不足惜后室,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望混狠。 院中可真熱鬧岸霹,春花似錦、人聲如沸将饺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽予弧。三九已至刮吧,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間掖蛤,已是汗流浹背杀捻。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蚓庭,地道東北人致讥。 一個(gè)月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像器赞,于是被迫代替她去往敵國和親垢袱。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,979評論 2 355