Spring Boot+SpringCloud实现MicroService微服务中的服务发现注册Eureka

本文介绍了如何在MicroService架构中使用Spring Cloud搭建Eureka服务发现和注册。通过Eureka,服务提供者可以注册到Eureka Server,而服务消费者则能发现并消费这些服务。详细步骤包括:创建父模块引入依赖,建立服务注册子模块、公共模块、服务提供模块和服务消费者模块,最后实现Eureka的单机和集群配置。

1.MicroService架构

SOA:面向服务的架构
微服务架构就是一种架构模式,将一个单体项目拆分为多个微服务,每个微服务可以独立技术选型,独立开发,独立部署,独立运维.并且多个服务相互协调,相互配合.

2.Springcloud

Springcloud是一个基于Spring Boot实现的服务治理工具包,在微服务架构中用于管理和协调服务的。
Springcloud其实就是一系列框架的有序集合,利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发

3.Springcloud有五大神兽

1.服务发现,注册 :Netflix Eureka
2.服务负载均衡 :Netflix Ribbon/Feign
3.断路器 : Netflix Hystrix
4.服务网关 : Netflix Zuul
5.分布式配置 : Netflix Config

4.使用Eureka

Eureka是一个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故障转移
有了服务发现和注册,只需要使用服务的标识符,就可以访问到服务,而不需要修改服务

4.1Eureka的三大角色

  1. Eureka server提供服务注册和发现,各个服务提供者节点启动后,会在Eureka Server中进行注册
  2. Service Provider服务提供方将自身服务注册到Eureka,从而使服务消费方能够找到
  3. Service Consumer服务消费方从Eureka获取注册服务列表,从而能够消费服务

4.2单机注册中心搭建

创建一个普通maven项目

4.2.1在父模块spingcloud-parent中引入依赖

限定springboot版本
限定springcloud版本

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<springboot.version>2.0.5.RELEASE</springboot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot<
Book Description Build a microservices architecture with Spring Boot, by evolving an application from a small monolith to an event-driven architecture composed of several services. This book follows an incremental approach to teach microservice structure, test-driven development, Eureka, Ribbon, Zuul, and end-to-end tests with Cucumber. Author Moises Macero follows a very pragmatic approach to explain the benefits of using this type of software architecture, instead of keeping you distracted with theoretical concepts. He covers some of the state-of-the-art techniques in computer programming, from a practical point of view. You'll focus on what's important, starting with the minimum viable product but keeping the flexibility to evolve it. What You'll Learn Build microservices with Spring Boot Use event-driven architecture and messaging with RabbitMQ Create RESTful services with Spring Master service discovery with Eureka and load balancing with Ribbon Route requests with Zuul as your API gateway Write end-to-end rest tests for an event-driven architecture using Cucumber Carry out continuous integration and deployment Who This Book Is For Those with at least some prior experience with Java programming. Some prior exposure to Spring Boot recommended but not required. Table of Contents Chapter 1: Introduction Chapter 2: The Basic Spring Boot Application Chapter 3: A Real Three-Tier Spring Boot Application Chapter 4: Starting with Microservices Chapter 5: The Microservices Journey Through Tools Chapter 6: Testing the Distributed System Appendix A: Upgrading to Spring Boot 2.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值