前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringCloud-Eureka【入门案例】

SpringCloud-Eureka【入门案例】

作者头像
用户4919348
发布2019-05-31 10:53:43
4160
发布2019-05-31 10:53:43
举报
文章被收录于专栏:波波烤鸭波波烤鸭

一、 什么是服务注册中心

  服务注册中心是服务实现服务化管理的核心组件,类似于目录服务的作用,主要用来存储服务信息,譬如提供者 url 串、路由信息等。服务注册中心是 SOA 架构中最基础的设施之一。

1 服务注册中心的作用

  1. 服务的注册
  2. 服务的发现

2 常见的注册中心有哪些

  1. Dubbo 的注册中心 Zookeeper
  2. Sringcloud 的注册中心 Eureka

3 服务注册中心解决了什么问题

  1. 服务管理
  2. 服务的依赖关系管理

4 什么是 Eureka 注册中心

  Eureka 是 Netflix 开发的服务发现组件,本身是一个基于 REST 的服务。Spring Cloud将它集成在其子项目 spring-cloud-netflix 中,以实现 Spring Cloud 的服务注册于发现,同时还提供了负载均衡、故障转移等能力。

5 Eureka 注册中心三种角色

5.1Eureka Server

  通过 Register、Get、Renew 等接口提供服务的注册和发现。

5.2Application Service (Service Provider)

  服务提供方把自身的服务实例注册到 Eureka Server 中

5.3Application Client (Service Consumer)

  服务调用方通过 Eureka Server 获取服务列表,消费服务

二、 Eureka入门案例

1.创建SpringBoot项目

  创建一个SpringBoot项目

2.引入相关的依赖

  添加如下的相关依赖

代码语言:javascript
复制
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
        <version>1.4.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
        <version>1.3.2.RELEASE</version>
    </dependency>
</dependencies>

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

创建启动器

  在启动类中我们需要放开@EnableEurekaServer,表明这是个Eureka的服务端

代码语言:javascript
复制
@EnableEurekaServer
@SpringBootApplication
public class SpringcloudEurekaDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudEurekaDemoApplication.class, args);
    }
}

修改application.properties文件

代码语言:javascript
复制
spring.application.name=eureka-server
server.port=8761

# 是否将自己注册到Eureka中,默认true
eureka.client.register-with-eureka=false
# 是否从Eureka服务中获取注册信息默认是true
eureka.client.fetch-registry=false

启动服务访问web页面

在这里插入图片描述
在这里插入图片描述

服务端启动成功~ 下篇介绍服务端的HA(高可用)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年05月27日,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、 什么是服务注册中心
    • 1 服务注册中心的作用
      • 2 常见的注册中心有哪些
        • 3 服务注册中心解决了什么问题
          • 4 什么是 Eureka 注册中心
            • 5 Eureka 注册中心三种角色
              • 5.1Eureka Server
              • 5.2Application Service (Service Provider)
              • 5.3Application Client (Service Consumer)
          • 二、 Eureka入门案例
            • 1.创建SpringBoot项目
              • 2.引入相关的依赖
                • 创建启动器
                  • 修改application.properties文件
                    • 启动服务访问web页面
                    相关产品与服务
                    微服务引擎 TSE
                    微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
                    领券
                    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档