• [Alibaba微服务技术入门]_第一个Sentinel程序_第11讲


    第一个Sentinel程序的准备工作

    • 启动Nacos,端口8848
    • 启动Sentinel,端口8080
    • 初始化5-sentinel-service6001的微服务

    第一步:创建5-sentinel-service6001的微服务工程

     第二步:导入依赖包

    <?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>alibaba</artifactId>
            <groupId>com.liuyangjava</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.liuyangjava</groupId>
        <artifactId>5-sentinel-service6001</artifactId>
    
        <dependencies>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            </dependency>
    
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            </dependency>
    
            <!--springcloud ailibaba sentinel-datasource-nacos 后续做持久化用到-->
            <dependency>
                <groupId>com.alibaba.csp</groupId>
                <artifactId>sentinel-datasource-nacos</artifactId>
            </dependency>
        </dependencies>
    
    </project>

    第三步:编写application.yml文件

    server:
      port: 6001
    
    spring:
      application:
        name: sentinel-service
      cloud:
        nacos:
          discovery:
            server-addr: 127.0.0.1:8848
        sentinel:
          transport:
            port: 8719
            dashboard: 127.0.0.1:8080
    
    management:
      endpoints:
        web:
          exposure:
            include: '*'

    第四步:编写FlowLimitController

    package com.liuyangjava.controller;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class FlowLimitController {
        @Value("${server.port}")
        private String port;
    
        @GetMapping("/sentinel/service")
        public String getInfo() {
            return "sentinel service is running, server port: " + port;
        }
    }

    第五步:编写SentinelService6001启动类

    package com.liuyangjava;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    
    @SpringBootApplication
    @EnableDiscoveryClient
    public class SentinelService6001 {
        public static void main(String[] args) {
            SpringApplication.run(SentinelService6001.class, args);
        }
    }

    第六步:启动Nacos

     第七步:启动Sentinel

     第八步:启动5-sentinel-service6001微服务

     第九步:进入到Sentinel后台管理界面,我们通过请求5-sentinel-service6001微服务的"/sentinel/service"接口,观察Sentinel后台管理界面的变化

     

     

  • 相关阅读:
    最长回文子串 V2(Manacher算法)
    用例建模Use Case Modeling
    分析一套源代码的代码规范和风格并讨论如何改进优化代码
    结合工程实践选题调研分析同类软件产品
    如何提高程序员的键盘使用效率
    antd移动端onClick事件点击无效
    webpack打包问题
    centos下部署项目问题
    javascript return 跟 break区别
    VUE清除组件内部定时器
  • 原文地址:https://www.cnblogs.com/liuyangjava/p/15513604.html
Copyright © 2020-2023  润新知