前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >eureka注册中心原理_腾讯实名认证中心

eureka注册中心原理_腾讯实名认证中心

作者头像
全栈程序员站长
发布2022-09-24 13:18:58
2.7K0
发布2022-09-24 13:18:58
举报

大家好,又见面了,我是你们的朋友全栈君。

英文版的官方教程

搭建Eruka注册中心很简单,三个步骤 1 增加项目依赖,改pom文件

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
    <relativePath/>
</parent>


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Greenwich.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

2 为Eruka新增配置文件

代码语言:javascript
复制
server.port=9000
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

3 启动类加@EnableEurekaServer注解

代码语言:javascript
复制
package com.yulisao.eruka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServer {
	public static void main(String[] args) {
		SpringApplication.run(EurekaServer.class, args);
	}
}

以上三个步骤。这篇文章很详细 (此文看上半部分即可,下半部分是搭建多个Eruka集群,他们之间可相互通讯同步)。新建一个boot项目,里面只需要pom文件、配置文件Application.properties,和启动类三个文件就可以了。

Eruka一般不是单点的, 因为一旦单点的eruka出点问题就要凉了,所以会集群。微服务启动后会向Eureka注册,并且周期性(默认30秒)向Eureka发送心跳,以证明当前服务是可用状态。Eureka在规定的时间内(默认90秒)一直未收到服务端的心跳,则认为服务已死掉(实际上不一定死掉了,也可能是网络通讯问题),会把服务的状态置为down并发布给订阅者,此时再调这个服务就调不通了。这个死掉的服务的事情也会同步告知其他eruka兄弟们。 Eureka 有自我保护机制,在配置文件里面加上eureka.server.enable-self-preservation=true,这样当短时间内大片死掉时,eruka不再注销服务,没加这行收不到心跳是会注销服务的。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/171853.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
微服务引擎 TSE
微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档