网站标题怎么设置,app网站开发长沙,wordpress 手机支付,百度竞价网站consul下载安装及使用 1.consul简介
Consul是一种开源的、分布式的服务发现和配置管理工具#xff0c;能够帮助开发人员构建和管理现代化的分布式系统。它提供了一套完整的功能#xff0c;包括服务注册与发现、健康检查、KV存储、多数据中心支持等#xff0c;可以帮助开发人…
consul下载安装及使用 1.consul简介
Consul是一种开源的、分布式的服务发现和配置管理工具能够帮助开发人员构建和管理现代化的分布式系统。它提供了一套完整的功能包括服务注册与发现、健康检查、KV存储、多数据中心支持等可以帮助开发人员简化系统的管理和维护工作。 2.consul下载
官网地址www.consul.io
源码地址GitHub - spring-cloud/spring-cloud-consul: Spring Cloud Consul
下载地址Install | Consul | HashiCorp Developer
支持多种操作系统以windows为例 3.安装检查
windows版下载后只有一个exe文件在对应路径下打开命令窗口输入consul --version
出现以下信息说明可以使用。 4.启动
开发模式启动consul命令行输入consul agent -dev
通过以下地址访问consul首页http://localhost:8500 5.服务注册 maven依赖 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-consul-discovery/artifactId/dependency 配置文件 启动类添加EnableDiscoveryClient注解
注意
使用consul服务名进行请求默认是开启负载均衡的调用时需要使用LoadBalanced注解。
Configuration
public class RestTemplateConfig {BeanLoadBalancedpublic RestTemplate restTemplate() {return new RestTemplate();}}6.consul配置中心
maven依赖
dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-bootstrap/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-consul-config/artifactId/dependency
bootstrap.yml
spring:application:name: cloud-payment-servicecloud:consul:host: localhostport: 8500discovery:service-name: ${spring.application.name}config:profile-separator: -format: yaml
启动类开启动态刷新RefreshScope
consul Key/Value配置 请求接口
public ResultString getInfo(Value(${mybootstrap.info}) String info) {return Result.success(port: port \t Info: info);
}
效果