注册中心


git地址:https://github.com/sunuanwuhou/SpringCloud2020.git

项目搭建

父工程项目搭建

  • dependencyManagement只是申明依赖了,不引入依赖
    子类不指定使用父类依赖,指定使用指定的。
  • mvn install

支付模块搭建

  1. payment8081模块
  • 建moudle
  • 改pom
  • 写yml
  • 主启动
  • 业务类

热部署

spring-boot-devtools

我这边用的是jrebel

消费者订单模块

  • 建moudle
  • 改pom
  • 写yml
  • 主启动
  • 业务类

20版idea是service 多个微服务

如果不出来,google解决

Eureka

服务治理

实现服务发现、注册、服务调用、负载均衡、容错

服务注册

image

2个组件

Eureka Server提供服务注册服务

Eureka Client通过注册中心访问

如果Eureka Server在多个心跳周期没有接收到某个节点的心跳,Eureka Server将会从服务注册中心把这个服务节点移除(默认90秒)

注意:这里会有一个考点:
Eureka心跳机制的实现

集群原理

互相注册,相互守望

信息完善

  instance:
    hostname: ${spring.cloud.client.ip-address}
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
    

Discovery

对于注册Eureka的服务,可以通过服务发现来获得服务信息

  public Object discovery() {
        List<String> services = discoveryClient.getServices();

        for (String service : services) {
            log.info("*****element:" + service);
        }

        List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PAYMENT-SERVICE");
        for (ServiceInstance instance : instances) {
            log.info(instance.getServiceId()+"\t" + instance.getHost() +
                    "\t" + instance.getPort() +"\t" + instance.getUri());
        }

        return  this.discoveryClient;
    }

自我保护

https://www.cnblogs.com/xishuai/p/spring-cloud-eureka-safe.html

zookeeper

cp

@EnableDiscoveryClient //该注解用于向使用consul或者zookeeper作为注册中心时注册服务

consul

https://www.consul.io/

三种注册中心

image

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值