当前位置 博文首页 > 蜗牛为梦想而生H:04-注册中心之Consul
eureka学习了那么多,但是eureka已经停止维护了,springCloud在Greenwich将netflix的一些组件改成了维护模式 (维护模式意味着这些组件不会有太大的更新了 只会修改大的bug以及安全问题),当然目前来看可以使用,但是从长远的角度考虑很显然不够优雅 ? 注意: 注意consoul不属于netflix家族的组件 而是另外一个对SpringCloud规范的一个实现
2. Consul能做什么
服务注册发现: Consul客户能够注册一个服务,比如api或mysql,其他客户可以在Consul上查询一个指定服务的提供者。Consul提供DNS和HTTP的服务发现接口。 ? 健康检查: Consul可以灵活的使用脚本等来检测注册在其上的服务是否可用,不健康的服务Consul也能够灵活处理,比如提供服务的主机内存使用超过90%,我们可以配置让Consul不要把这样的服务提供给服务调用者。 ? key/value存储: 这个功能和etcd有些类似,可以通过HTTP API方便地使用。 ? 多数据中心支持: Consul支持开箱即用的多数据中心支持,这意味着用户不用建立额外的抽象层让业务扩展到各个区域。
3. consul的官网下载
?
注意点
consul和eureka都可以做注册中心,但是eureka的注册中心其实就是一个工程(我们只需要添加服务端的依赖即可),但是consul的使用必须要安装后 才可以使用
下载解压
?
?
启动和关闭
## 启动命令 consul agent -dev ? ## 关闭命令 consul leave
启动测试
访问地址
?
?
4. 接入consul
4.1. 新建consul-provider
?
4.2. 添加依赖
<dependencies> ? ? ? ?<!--监控可选 可以不加--> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.boot</groupId> ? ? ? ? ? ?<artifactId>spring-boot-starter-actuator</artifactId> ? ? ? ?</dependency> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.boot</groupId> ? ? ? ? ? ?<artifactId>spring-boot-starter-web</artifactId> ? ? ? ?</dependency> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.cloud</groupId> ? ? ? ? ? ?<artifactId>spring-cloud-starter-consul-discovery</artifactId> ? ? ? ?</dependency> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>com.cloud.cn</groupId> ? ? ? ? ? ?<artifactId>cloud-entity</artifactId> ? ? ? ? ? ?<version>1.0-SNAPSHOT</version> ? ? ? ?</dependency> ? ?</dependencies>
4.3. 编写主配置类
?
4.4. 编写控制器
?
4.5. 编写配置文件
?
4.6. 启动测试
?
4.7. 新建consul-consumer
?
4.8. 添加依赖
<dependencies> ? ? ? ?<!--监控可选 可以不加--> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.boot</groupId> ? ? ? ? ? ?<artifactId>spring-boot-starter-actuator</artifactId> ? ? ? ?</dependency> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.boot</groupId> ? ? ? ? ? ?<artifactId>spring-boot-starter-web</artifactId> ? ? ? ?</dependency> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.cloud</groupId> ? ? ? ? ? ?<artifactId>spring-cloud-starter-consul-discovery</artifactId> ? ? ? ?</dependency> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>com.cloud.cn</groupId> ? ? ? ? ? ?<artifactId>cloud-entity</artifactId> ? ? ? ? ? ?<version>1.0-SNAPSHOT</version> ? ? ? ?</dependency> ? ?</dependencies>
4.9. 编写主配置类
?
4.10. 编写控制器
?
4.11. 编写配置文件
?
4.12. 启动测试
?
4.13. 远程调用测试
?
4.14. 集群搭建
集群搭建
cs下一篇:没有了
最新 更多<<
蜗牛为梦想而生H:04-注册中心之Consul 创建一个ASP.NET MVC5项目的实现方法(图文) 蜗牛为梦想而生H:05-注册中心之nacos .NET Core下使用Kafka的方法步骤 .NET Core下使用Log4Net记录日志的方法步骤 蜗牛为梦想而生H:06-负载均衡之Ribbon .NET CORE3.1实现微信小程序发送订阅消息 在.NET中使用DiagnosticSource的方法 蜗牛为梦想而生H:09-熔断器Hystrix ASP.NET Core 实现基本认证的示例代码 深入解读ASP.NET Core身份认证过程实现 Asp.Net Core 企业微信静默授权的实现 手把手教你AspNetCore WebApi认证与授权的方法 手把手教你AspNetCore WebApi数据验证的实现 .NET Core使用FluentEmail发送邮件的示例代码 .Net Core中使用Grpc的方法 UrlRewrite概念原理及使用方法解析 蜗牛为梦想而生H:流量防卫兵sentinel Docker结合.Net Core的初步使用教程 蜗牛为梦想而生H:JAVA8 之 Stream sorted() 示例,排序 .Net Core3.0 配置Configuration的实现 .NET Core3.0创建Worker Services的实现 蜗牛为梦想而生H:SQL加减乘除 .NET Core3.0 日志 logging的实现 蜗牛为梦想而生H:过滤器无法取值RedisTemplate , 为Null解决方 详解ASP.NET Core 反向代理部署知多少 蜗牛为梦想而生H:RedisTemplate.keys() 替换为Scan 扫描指定Key net core webapi多版本控制与swagger(nswag)配置教程 蜗牛为梦想而生H:RedisAtomicInteger原子自增 .NET Core使用Topshelf方式创建Windows服务的全过程记录