springcloud

启用熔断

application.properties中需要配置

# 必需加这个
feign.hystrix.enabled=true
@FeignClient(name = "demosvc",
    contextId = "DemoClient",
    // 得使用fallback
    fallback = DemoFallback.class,
    path = "/svc/demo")
public interface DemoClient {
    @PostMapping("/findByName.do")
    ResponseEntity<Demo> findByName(@RequestBody String name);
}
// 这个注解得加,不然服务启动不了
@Component
public class DemoFallback implements DemoClient {
    @Override
    public ResponseEntity<Demo> findByName(String name) {
        return ResponseEntity.ok(new Demo());
    }
}
@EnableFeignClients
@SpringCloudApplication
// 加不加这个这个都能正常使用
@EnableHystrix
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

Eureka

eureka 架构原理

cap原则

cap

cap2

registry

优雅停服

使用actuator。

management:
  endpoints:
    web:
      exposure:
        include: shutdown        
  endpoint:
    shutdown:
      enable: true  # 开启shutdown实现优雅停服

往业务服务发送post请求:

curl XPOST http://ip:port/actuator/shutdown

作者:张三  创建时间:2024-12-26 19:46
最后编辑:张三  更新时间:2024-12-26 19:46