zoukankan      html  css  js  c++  java
  • spring cloud config搭建说明例子(三)-添加actuator

    添加心跳

    服务端 ConfigServer

    pom.xml添加actuator包

    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-config-server</artifactId>
    		</dependency>
                    <dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-eureka-server</artifactId>
    		</dependency>
    		<dependency>
    		    <groupId>org.springframework.boot</groupId>
    		    <artifactId>spring-boot-starter-actuator</artifactId>
    		</dependency>
    

    spring-cloud-starter-eureka与spring-cloud-starter-eureka-server的区别?

    app不变

    @EnableDiscoveryClient
    @EnableConfigServer
    public class ConfigServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(ConfigServerApplication.class, args);
        }
    }
    

    @EnableDiscoveryClient与@EnableEurekaClient的区别?

    application.yml添加healthcheck

    server:
       port: ${PORT:8888}                                #配置工程端口号
    
    spring:
       application:
          name: cloud-config-server                     #设置该服务应用名称
       profiles:
          active: native                                 #设置读取为本地工程文件
       config:
          server:
             native:
                searchLocations: classpath:/config       #配置文件根目录,也就是XXX-dev.properties等的目录
    
    #注册到eureka服务中心进行监控
    eureka:
       client:
          serviceUrl:
              defaultZone: http://eureka:eureka@localhost:8761/eureka # 可以逗号分隔,配置多个
          healthcheck:
              enabled: true                                                         #开启健康监控
       instance:
          prefer-ip-address: true
          instanceId: ${spring.application.name}:${spring.application.instance_id:${server.port}}
          leaseRenewalIntervalInSeconds: 30 
          leaseExpirationDurationInSeconds: 90
    

    官网也用发发发发这个端口。

    配置文件

    新建配置文件:
    XXX-dev.properties
    XXX-test.properties

    客户端AppClient

    pom.xml也需要增加autuator

    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-web</artifactId>
    	</dependency>
    	<dependency>
    		<groupId>org.springframework.cloud</groupId>
    		<artifactId>spring-cloud-starter-config</artifactId>
    	</dependency>
            <dependency>
    		<groupId>org.springframework.cloud</groupId>
    		<artifactId>spring-cloud-starter-eureka</artifactId>
    	</dependency>
    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-actuator</artifactId>
    	</dependency>
    

    bootstrap.properties配置不变

    spring.cloud.config.name=XXX
    spring.cloud.config.profile=dev
    #spring.cloud.config.profile=test
    spring.cloud.config.uri=http://localhost:8888/ # 只能配置一个,不能逗号分隔配置多个config
    

    application.yml配置,和config一样增加health

    server:
       port: 8080                                  #设置当前服务端口
       context-path: /abc                          #设置服务上下文路径
    
    spring:
       application:
          name: app-client                  #service name 设置当前服务名称
    
    eureka:
       client:
          serviceUrl:
              defaultZone: http://eureka:eureka@localhost:8761/eureka   # 可以逗号分隔,配置多个
          healthcheck:
              enabled: true
       instance:
          prefer-ip-address: true                              # 注册到Eureka Server上的是IP
          instanceId: ${spring.application.name}:${spring.application.instance_id:${server.port}}
          leaseRenewalIntervalInSeconds: 15                    # 心跳时间,即服务续约间隔时间(缺省为30s)  
          leaseExpirationDurationInSeconds: 45                  # 发呆时间,即服务续约到期时间(缺省为90s)
    

    application类不变

    @SpringBootApplication
    @EnableEurekaClient
    public class ClientApplication {
    
    	public static void main(String[] args) throws Exception {
    		SpringApplication.run(ClientApplication.class, args);
    	}
    }
    

    参考资料:
    spring cloud config搭建说明例子(二)

  • 相关阅读:
    微信第三方登录,ios第三方登录(没有进行二次封装,直接调用)
    How Do I Declare A Block in Objective-C?
    Android与JS混编(js调用java)
    React-Native做一个文本输入框组件
    如何在程序退出的时候清除activity栈
    React react-ui-tree的使用
    React-Native OpenGL体验二
    React-Native OpenGL体验一
    react-native使用react-art制作SVG动画
    Android画一个随意拖动的圆形
  • 原文地址:https://www.cnblogs.com/ouyida3/p/9125413.html
Copyright © 2011-2022 走看看