天天看点

Spring Cloud Alibaba入门实践(八)-微服务接入Sentinel

先把mall-order服务接入Sentinel,修改mall-order服务的application.yml,加上有关Sentinel控制台的配置 ,如下:

Spring Cloud Alibaba入门实践(八)-微服务接入Sentinel

再新建个测试类TestController,用来测试了解Sentinel各种规则,如下:

package com.example.mallorder.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class TestController {

    @GetMapping("/order/message1")
    public String message1() {
        return "message1";
    }

    @GetMapping("/order/message2")
    public String message2() {
        return "message2";
    }
}
           

启动mall-order服务,由于控制台是懒加载机制的,所以先访问下测试接口http://localhost:10020/order/message1,然后看下控制台信息:

Spring Cloud Alibaba入门实践(八)-微服务接入Sentinel

可以看到控制台已经接入了mall-order服务。

接下来就是通过mall-order服务,来一一了解下各种规则的使用。