天天看點

spring cloud 實踐坑點記錄

用spring cloud 微服務架構有一段時間了有一些坑點在這裡給大家記錄一下希望大家用得着

1、當我們使用聚合性能監控的時候,我們采用 rabbitmq作為消息中間件來收集性能資訊最後在使用TurbineStream将資訊進行聚合

  這個工具聚合是根據“應用名+方法名”進行求和彙總的

  如下代碼:

  

@HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "20000") }, threadPoolProperties = {
                    @HystrixProperty(name = "coreSize", value = "64") }, threadPoolKey = "test1")
    @GetMapping("/testpro3")
    public int getStringtest2(){

        //throw new Exception("ddd");
        return 1;
    }      

  這裡的聚合就是“應用名+getStringtest2”

spring cloud 實踐坑點記錄

  這樣的話就會存在一個問題在不同的兩個類都是被@RestController标記并且都對外釋出接口的url不同功能也不同

  如下:

@RestController
public class testRest1 {
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "20000") }, threadPoolProperties = {
                    @HystrixProperty(name = "coreSize", value = "64") }, threadPoolKey = "test1")
    @GetMapping("/testpro3")
    public int getStringtest2(){

        //throw new Exception("ddd");
        return 1;
    }
}      
@RestController
public class testRest1 {
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "20000") }, threadPoolProperties = {
                    @HystrixProperty(name = "coreSize", value = "64") }, threadPoolKey = "test1")
    @GetMapping("/testpro4")
    public int getStringtest2(){

        //throw new Exception("ddd");
        return 1;
    }
}      

  假如像上面的代碼在一個工程裡面就會吧這兩個方法的性能進行聚合,可能我們在項目中很少出現這種情況但是 墨菲定律 有可能發生的事情就一定會發生

2、配置檔案伺服器重新整理坑點

  當我們的spring boot應用使用配置中心進行配置加載的時候,當我們的配置檔案更新的時候去重新整理通知我們的URL通常是這樣的

  10.10.12.51:8888/bus/refresh?destination=spring-cloud-demo:8082進行post請求

  上面的url是沒問題的但是我們可能會看到EUREKA注冊中心對應用名全是大寫的 如下

spring cloud 實踐坑點記錄

  這樣就會給我們一個誤導是不是用全部是大寫的應用名也可以啊??向下面這樣

10.10.12.51:8888/bus/refresh?destination=SPRING-CLOUD-DEMO:8082      

  經過測試這樣是不行的,是以請大家注意

服務監控資訊到底是“主動推送”還是“被動掃描”??? spring boot +RabbitMQ +InfluxDB+Grafara監控實踐