SpringCloud 的服务注册和发现是由Eureka来完成。

1.eureka server

1.1 依赖

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

1.2 @EnableEurekaServer 注册服务

@SpringBootApplication
@EnableEurekaServer //开启服务注册中心
public class EurekaServerApplication
{ public static void main(String[] args)
{
SpringApplication.run(EurekaServerApplication.class, args);
}
}

1.3. 配置

server:
port: 8761
eureka:
instance:
hostname: localhost
client:
# 表示本应用是否是向注册中心注册自己
register-with-eureka: false
# 是否检索服务
fetch-registry: false

2. eureka client

2.1 依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

2.2  @EnableDiscoveryClient

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

2.3 配置

eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
# 客户端名称
instance:
hostname: client-
spring:
application:
# 注册到服务端名称
name: eureka-client
# 客户端端口
server:
port:

3.高可用

3.1 服务端配置(配置3个服务端)

server1

#服务名
spring.application.name=eureka-server #注册中心- 端口
server.port= #注册中心主机名
eureka.instance.hostname=server1 #指定另外的注册中心
eureka.client.serviceUrl.defaultZone=http://server2:1002/eureka/,http://server3:1003/eureka/

server2

#服务名
spring.application.name=eureka-server #注册中心- 端口
server.port= #注册中心主机名
eureka.instance.hostname=server2 #指定另外的注册中心
eureka.client.serviceUrl.defaultZone=http://server1:1001/eureka/,http://server3:1003/eureka/

server3

#服务名
spring.application.name=eureka-server #注册中心- 端口
server.port= #注册中心主机名
eureka.instance.hostname=server3 #指定另外的注册中心
eureka.client.serviceUrl.defaultZone=http://server1:1001/eureka/,http://server2:1002/eureka/

3.2 客户端配置

#设置服务名
spring.application.name=eureka-client #指定服务注册中心地址
eureka.client.service-url.defaultZone=http://server1:1001/eureka/,http://server2:1002/eureka/,http://server3:1003/eureka/

4.启动时配置端口

java -jar eureka-service-1.0-SNAPSHOT.jar –server.port= 

SpringCloud - 2. 服务注册 和 发现的更多相关文章

  1. 将SpringCloud Eureka 服务注册与发现部署到docker

    一.前言 最近在学习docker,顺便把之前学习的spring cloud 部署到Docker 中.至于什么是SpringCloud的服务注册与发现,什么是docker,我这里就不作赘述了.可以先去学 ...

  2. springcloud之服务注册与发现(Eureka)

    springcloud服务注册与发现 使用Eureka实现服务治理 作用:实现服务治理(服务注册与发现) 简介: Spring Cloud Eureka是Spring Cloud Netflix项目下 ...

  3. springcloud之服务注册与发现(zookeeper注册中心)-Finchley.SR2版

    新年第一篇博文,接着和大家分享springcloud相关内容:本次主要内容是使用cloud结合zookeeper作为注册中心来搭建服务调用,前面几篇文章有涉及到另外的eureka作为注册中心,有兴趣的 ...

  4. springcloud之服务注册与发现

    本次分享的是关于springcloud服务注册与发现的内容,将通过分别搭建服务中心,服务注册,服务发现来说明:现在北京这边很多创业公司都开始往springcloud靠了,可能是由于文档和组件比较丰富的 ...

  5. SpringCloud(二) 服务注册与发现Eureka

    1.eureka是干什么的? 上篇说了,微服务之间需要互相之间通信,那么通信就需要各种网络信息,我们可以通过使用硬编码的方式来进行通信,但是这种方式显然不合适,不可能说一个微服务的地址发生变动,那么整 ...

  6. 微服务SpringCloud之服务注册与发现

    在找.net core 微服务框架时发现了Steeltoe开源项目,它可以基于Spring Cloud实现.net core和.net  Framework的微服务.正好之前也有学习过SpringBo ...

  7. SpringCloud Eureka服务注册及发现——服务端/客户端/消费者搭建

    Eureka 是 Netflix 出品的用于实现服务注册和发现的工具. Spring Cloud 集成了 Eureka,并提供了开箱即用的支持.其中, Eureka 又可细分为 Eureka Serv ...

  8. springcloud(第三篇)springcloud eureka 服务注册与发现 *****

    http://blog.csdn.net/liaokailin/article/details/51314001 ******************************************* ...

  9. SpringCloud(2) 服务注册和发现Eureka Server

    一.简介 EureKa在Spring Cloud全家桶中担任着服务的注册与发现的落地实现.Netflix在设计EureKa时遵循着AP原则,它基于REST的服务,用于定位服务,以实现云端中间层服务发现 ...

随机推荐

  1. 修改chrome插件

    背景 例子为:ModHeader插件,顾名思义可以修改request header的插件,官方地址为:https://chrome.google.com/webstore/detail/modhead ...

  2. 解决ImageCropperComponent发布报错

    ng serve可以正常运行,npm run build 就会报错: ERROR in : Type ImageCropperComponent in -/node_modules/ng2-img-c ...

  3. 开发者常用的十款Chrome插件

    本文是稀土掘金投稿,虽然其中有倔金的私货,是篇推广文,但我看过后认为内容确实不错,有些好插件还是第一次知道,对我很有帮助,考虑过后还是决定推荐给大家,最近我比较关注各种提高开发效率的工具与技巧,今后看 ...

  4. 如何让Gogland不过期,一直使用?

    Gogland是jetBrains公司出品的GO语言开发IDE,是目前最好的GO语言开发工具!!但是目前Gogland提供的试用版,有一定的使用期限,如何到期还能使用?经过我的测试,如果Gogland ...

  5. Unity下的开发框架--适应web和微端游戏异步资源请求的框架

    一.   内容简介: 1.   框架对Web与微端游戏特性的支持: Web和微端游戏最重要的特性是,资源是持续从服务器上即时下载下来的.而保证体验流畅的关键就是保证资源下载分散到持续的体验过程中,并保 ...

  6. vuejs 添加事件时出现TypeError: n.apply is not a function

    vuejs项目中给表单元素添加事件时出现了TypeError: n.apply is not a function的错误,后来发现错误原因时处理事件的函数名和data中定义的变量名相同 当给事件添加处 ...

  7. win10开始菜单任务栏点击无反应

    win+r,输入powershell,确定,输入Stop-Process -Name explorer,回车(这行代码是结束explorer进程,结束后它会自动重启)

  8. hadoop-1.2.1-1.x86_64.rpm、jdk-7u45-linux-x64.tar.gz安装(64位)

    一,   配置信息 机器是64位,所以操作系统.软件都是64位的. 操作系统:CentOS6.2(64位): Hadoop是hadoop-1.2.1-1.x86_64.rpm: JDK是jdk-7u4 ...

  9. npm start时报错 npm ERR!Windows_NT 6.1.7601

    练习webpack 时 输入 npm start就报这样的错.百度了一圈,都没有找到答案.于是,我开始看错误信息......................................../手动黑 ...

  10. CentOS6.5下telnet服务

    00×0 本文介绍Telnet搭建,以及展示这是一个不安全的远程服务. 00×1 服务准备工作 [root@localhost ~]# yum install xinetd telnet-server ...