之前我们讲了注册中心,也就是Eureka Server的使用,我们来讲一下服务注册,Eureka Client的使用,基本上第一件事就是把Eureka Server给启动起来nohup java -jar eureka-0.0.1-SNAPSHOT.jar &10.40.8.152:8761这就方便了不用每次都去启动它kill -9 4681我们要把一个应用注册到一个应用中心去,那你要往哪个地址注册,你总得配置一下,不然我怎么知道往哪注册呢,eureka.client.serviceUrl.defaultZone=http://admin:1234@localhost:8761/eureka在启动类上加注解@EnableEurekaClient@EnableEurekaClient
@SpringBootApplication
public class ClientApplication {public static void main(String[] args) {SpringApplication.run(ClientApplication.class, args);}
}@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@EnableDiscoveryClient
public @interface EnableEurekaClient {}奇怪的是这个应用名怎么叫UNKNOWN,我们来改一下名字spring.application.name=client这就是修改应用的名字有的时候我们希望点过来是另外一个地址,他不是这个IP,这个我们怎么做到自定义呢http://10.40.8.144:7900/info配置里面有这么一个属性eureka.instance.hostname=clientNameemergency! eureka may be incorrectly claiming instances are up when they're not. renewals are lesser than threshold and hence the instances are not being expired just to be safe.如果你不停的重启,会导致一个什么问题呢,可能会出现一串警告了,Eureka Server端和这些应用,Client端他们采用的是心跳的机制,Server端会不停的去检查,Client端是否还存活,那么他会在一定的时间统计出来,上线率,就是一个比例,定义某个比例的时候呢,就会爆出这么一个警告,意思就是说,你这个client上线率太低了,可能我都不知道你是上线还是下线,那么怎么办呢,那么我就当做你是上线,就是宁可信其有,不可信其无,这其实是他的一种自我保护的模式,当然在开发环境,可以把它给关掉,避免你以后要来调用这个微服务的时候,这上面展示的在线,实际上他已经是下线状态了,所以开发环境我们最好给他关掉eureka.server.enableSelfPreservation=false这个配置你只能在开发环境把它关闭,生产环境一定不要这么来设置,你要往哪个注册地址去注册,你要配置上的,配置完了启动了,其实还是不能注册上去,你要在启动主类上加上注解@EnableEurekaClient,然后再看看我们的配置,你如果有需要的话呢,可以加上,给他起一个别名,另外应用的名字你最好给他写上,不然应用的名字显示的就是UNKNOWN,Eureka Server的自我保护,开发环境你可以把它给关闭,这样方便以后我们做微服务的调用,不会出错
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.learn</groupId><artifactId>client</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><parent><groupId>cn.learn</groupId><artifactId>microcloud02</artifactId><version>0.0.1</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><thymeleaf.version>3.0.9.RELEASE</thymeleaf.version><thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version></properties><dependencies><!-- Spring Boot进行单元测试的模块 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency></dependencies><!-- 这个插件,可以将应用打包成一个可执行的jar包 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.learn</groupId><artifactId>microcloud02</artifactId><version>0.0.1</version><packaging>pom</packaging><name>microcloud02</name><url>http://maven.apache.org</url><!-- <modules><module>microservice-hystrix-dashboard</module></modules> --><properties><jdk.version>1.8</jdk.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencyManagement><dependencies><dependency>    <groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Dalston.SR1</version><type>pom</type><scope>import</scope></dependency><dependency>    <!-- SpringCloud离不开SpringBoot,所以必须要配置此依赖包 --><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>1.5.12.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><!-- <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build> --></project>
#debug=true
server.port=7900logging.level.com.learn=trace
logging.file=springboot.log
logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%neureka.client.serviceUrl.defaultZone=http://admin:1234@10.40.8.152:8761/eurekaspring.application.name=client
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
#eureka.instance.hostname=clientName
package com.learn.cloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@EnableEurekaClient
@SpringBootApplication
public class ClientApplication {public static void main(String[] args) {SpringApplication.run(ClientApplication.class, args);}
}

Eureka Client的使用相关推荐

  1. SpringCloud Eureka Client和Server侧配置及Eureka高可用配置

    一.Eureka注册中心和客户端配置Demo. 1.Server端 a.使用Idea创建Spring项目,如下所示: b.相关配置 application.yaml配置文件如下: # eureka本身 ...

  2. Spring Cloud Netflix Eureka client源码分析

    1.client端 EurekaClient提供三个功能: EurekaClient API contracts are: * - provide the ability to get Instanc ...

  3. Spring Cloud(二) 配置Eureka Client

    前文回顾: Spring Cloud(一)Eureka Server-单体及集群搭建 本节我们将创建两个Eureka Client,注册到上节中的Eureka Server中,一个作为服务提供方,一个 ...

  4. 如何创建一个Eureka Client?

    EurekaInstanceConfig & EurekaClientConfig Instance 是实例的意思, EurekaInstanceConfig 就是 eureka client ...

  5. springcloud 之服务注册与发现 Eureka Client

    在上一篇文章中我们已经成功的搭建了一个基于springcloud eureka的服务发现与注册中心,但是我们并没有向其中注入任何服务实例,接下来我将教大家如何将现有的服务注册到我们自己的eureka注 ...

  6. Eureka Client注册到Eureka Server的秘密

    前言 我们知道Eureka分为两部分,Eureka Server和Eureka Client.Eureka Server充当注册中心的角色,Eureka Client相对于Eureka Server来 ...

  7. SpringCloud创建Eureka Client服务注册

    1.说明 本文详细介绍微服务注册到Eureka的方法, 即Eureka Client注册到Eureka Server, 这里用任意一个Spring Cloud服务为例, 比如下面已经创建好的Confi ...

  8. Spring Cloud微服务系列-Eureka Client源码解析(二)

    导语   上一篇博客中介绍了关于Eureka Client源码的基础部分,如果对于基础部分不是很了解的读者可以点击下面的连接进入到源码分析一中,从头开始学习 Spring Cloud微服务系列 Dis ...

  9. Spring Cloud微服务系列-Eureka Client源码解析(一)

    导语   Eureka Client 是为了简化开发人员的开发工作,将很多的Eureka Server交互的工作进行了封装,在使用的时候自动完成,在应用的不同阶段来完成不同的功能实现.下面就来了解一下 ...

最新文章

  1. Node.js express 之mongoose 从异步回调函数返回值,类似于同步
  2. INFO:安装包文件共享(Shared Files)设置注意事项
  3. (Ⅰ)基于Hexo+GitHub Page搭建博客,绑定域名及备份
  4. 使用mongoose来创建嵌入式websocket客户端和http客户端
  5. 百度缺的不是狼性,而是鲁滨逊
  6. oracle常见sql笔试题,一路SQL笔试题
  7. aspectjweaver AspectJ
  8. Java 定时任务JOB
  9. 有了5G手机和套餐,如何正确使用5G网络?
  10. 隐藏input的三种方法
  11. IOS App的生命周期
  12. python海龟教程_Python 零基础 快速入门 趣味教程 (咪博士 海龟绘图 turtle) 7. 条件循环...
  13. 云计算企业级小架构部署应用综合练习-二- Ansible 部署 Elastic Stack(ELK)
  14. uni-app触发点击事件
  15. 百面机器学习(13)——生成式对抗网络
  16. html中a标签的属性
  17. 转载:嵌入式系统综述之二
  18. “三色鸽杯”南阳市第四届十大新闻人物揭晓
  19. 漫画 | 妹子让我写个程序,我却搞砸了...
  20. 全面剖析页游巨头发家史(转)

热门文章

  1. POJ 1041 John's trip(欧拉回路)
  2. MySQL中的单引号
  3. R运行大数据的过程中遇到的问题:不能有负长度矢量
  4. 给定数组A,大小为n,现给定数X,判断A中是否存在两数之和等于X
  5. Excel文件弹出另存为代码
  6. 收集下关系数据库处理亿万级别的数据
  7. php面试专题---2、常量及数据类型考点
  8. docker快速入门01——docker安装与简单应用
  9. 解决 Intellij IDEA 文件图标一直闪烁
  10. 聚焦智造 共筑生态——“2016智能硬件生态圈品牌交流会”即将举行