SpringCloud创建Eureka Client服务注册
1.说明
本文详细介绍微服务注册到Eureka的方法,
即Eureka Client注册到Eureka Server,
这里用任意一个Spring Cloud服务为例,
比如下面已经创建好的Config Server模块,
请参考SpringCloud创建Config模块,
在里面创建Eureka Client配置,
把Config Server微服务注册到Eureka Server。
2.添加依赖
在pom.xml中增加eureka-client的依赖:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
3.添加配置
在application.yml中配置自己的主机名,
以及注册的Eureka地址:
eureka:
instance:
#eureka客户端的实例名字(主机名)
hostname: config-service
client:
service-url:
#表示向注册中心注册自己
register-with-eureka: true
#表示需要去注册中心检索服务
fetch-registry: true
#与eureka server交互的地址,包括查询服务和注册服务
defaultZone: http://localhost:7001/eureka
4.添加注解
在客户端的主启动类上面加EnableEurekaClient注解:
package com.yuwen.spring.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
5.启动服务
Config Server服务启动日志如下,
注意要先启动Eureka Server服务。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.1.RELEASE)
2020-09-09 16:43:54.699 INFO 11216 --- [ main] c.yuwen.spring.config.ConfigApplication : No active profile set, falling back to default profiles: default
2020-09-09 16:43:55.351 WARN 11216 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2020-09-09 16:43:55.473 INFO 11216 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=37338f68-d6d5-3a56-8d91-37021e6160dc
2020-09-09 16:43:56.076 INFO 11216 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9009 (http)
2020-09-09 16:43:56.086 INFO 11216 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-09-09 16:43:56.086 INFO 11216 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.36]
2020-09-09 16:43:56.203 INFO 11216 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-09-09 16:43:56.204 INFO 11216 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1491 ms
2020-09-09 16:43:56.264 WARN 11216 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-09-09 16:43:56.264 INFO 11216 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-09-09 16:43:56.278 INFO 11216 --- [ main] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@24534cb0
2020-09-09 16:43:56.350 WARN 11216 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-09-09 16:43:56.350 INFO 11216 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-09-09 16:43:56.563 INFO 11216 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-09 16:43:57.929 WARN 11216 --- [ main] ockingLoadBalancerClientRibbonWarnLogger : You already have RibbonLoadBalancerClient on your classpath. It will be used by default. As Spring Cloud Ribbon is in maintenance mode. We recommend switching to BlockingLoadBalancerClient instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
2020-09-09 16:43:57.978 INFO 11216 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-09-09 16:43:58.005 INFO 11216 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2020-09-09 16:43:58.059 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2020-09-09 16:43:58.119 INFO 11216 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2020-09-09 16:43:58.119 INFO 11216 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2020-09-09 16:43:58.234 INFO 11216 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2020-09-09 16:43:58.235 INFO 11216 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2020-09-09 16:43:58.394 INFO 11216 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2020-09-09 16:43:58.624 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2020-09-09 16:43:58.624 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2020-09-09 16:43:58.625 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2020-09-09 16:43:58.625 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2020-09-09 16:43:58.625 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2020-09-09 16:43:58.625 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2020-09-09 16:43:58.625 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2020-09-09 16:43:58.825 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2020-09-09 16:43:58.826 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2020-09-09 16:43:58.828 INFO 11216 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2020-09-09 16:43:58.831 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1599641038830 with initial instances count: 0
2020-09-09 16:43:58.832 INFO 11216 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application CONFIG-SERVER with eureka with status UP
2020-09-09 16:43:58.832 INFO 11216 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1599641038832, current=UP, previous=STARTING]
2020-09-09 16:43:58.834 INFO 11216 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-SERVER/yuwen-asiainfo:config-server:9009: registering service...
2020-09-09 16:43:58.859 INFO 11216 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9009 (http) with context path ''
2020-09-09 16:43:58.859 INFO 11216 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9009
2020-09-09 16:43:58.925 INFO 11216 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-SERVER/yuwen-asiainfo:config-server:9009 - registration status: 204
2020-09-09 16:43:59.150 INFO 11216 --- [ main] c.yuwen.spring.config.ConfigApplication : Started ConfigApplication in 5.648 seconds (JVM running for 6.129)
6.查看服务
这样客户端服务启动之后,
访问Eureka页面http://localhost:7001,
可以看到已经有CONFIG-SERVER注册了:
注意上面的两个红框,
分别对应微服务名称和主机名:
spring:
application:
# 微服务名称
name: config-server
eureka:
instance:
#eureka客户端的实例名字(主机名)
hostname: config-service
SpringCloud创建Eureka Client服务注册的更多相关文章
- 【微服务架构】SpringCloud之Eureka(服务注册和服务发现基础篇)(二)
上篇文章讲解了SpringCloud组件和概念介绍,接下来讲解一下SpringCloud组件相关组件使用.原理和每个组件的作用的,它主要提供的模块包括:服务发现(Eureka),断路器(Hystrix ...
- SpringCloud之Eureka(服务注册和服务发现基础篇)(二)
一:Eureka简介 Eureka是Spring Cloud Netflix的一个子模块,也是核心模块之一.用于云端服务发现,一个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故障转移. ...
- SpringCloud Netflix Eureka(服务注册/发现)
⒈Eureka是什么? Eureka是Netflix的一个子模块,也是核心模块之一,Eureka是一个基于REST的服务,用于定位服务以实现云端中间层服务发现和故障转移,服务注册与发现对于微服务架构来 ...
- SpringCloud2.0 Eureka Client 服务注册 基础教程(三)
1.创建[服务提供者],即 Eureka Client 1.1.新建 Spring Boot 工程,工程名称:springcloud-eureka-client 1.2.工程 pom.xml 文件添加 ...
- 最简单的懒人springcloud之Eureka(服务注册与发现)
本文开发软件是STS,是eclipse为springboot项目而生的一个软件,用这个软件开发spring的项目版本都会自己对应的,话不多说直接上代码 springboot版本2.1.8.RELEAS ...
- SpringCloud创建Config Client通过Eureka访问Config
1.说明 本文详细介绍配置中心客户端使用方法, 即Config Client到Config Server读取配置. 读取配置的方式有两种, 第一种是直接配置Configer Server的URL, 第 ...
- 【SpringCloud Eureka源码】从Eureka Client发起注册请求到Eureka Server处理的整个服务注册过程(下)
目录 一.Spring Cloud Eureka Server自动配置及初始化 @EnableEurekaServer EurekaServerAutoConfiguration - 注册服务自动配置 ...
- SpringCloud(二)- 服务注册与发现Eureka
离上一篇微服务的基本概念已经过去了几个月,在写那篇博客之前,自己还并未真正的使用微服务架构,很多理解还存在概念上.后面换了公司,新公司既用了SpringCloud也用了Dubbo+Zookeeper, ...
- 学习一下 SpringCloud (二)-- 服务注册中心 Eureka、Zookeeper、Consul、Nacos
(1) 相关博文地址: 学习一下 SpringCloud (一)-- 从单体架构到微服务架构.代码拆分(maven 聚合): https://www.cnblogs.com/l-y-h/p/14105 ...
随机推荐
- Mysql百万级数据索引重新排序
参考https://blog.csdn.net/pengshuai007/article/details/86021689中思路解决自增id重排 方式一 alter table `table_name ...
- Linux基础命令---htpasswd创建密码文件
htpasswd htpasswd指令用来创建和更新用于基本认证的用户认证密码文件.htpasswd指令必须对密码文件有读写权限,否则会返回错误码. 此命令的适用范围:RedHat.RHEL.Ubun ...
- Vue重要知识
Event Bus 总线 Vue中的EventBus是一种发布订阅模式的实践,适用于跨组件简单通信. Vuex也可以用来组件中进行通信,更适用于多组件高频率通信. 使用方式: 1.把Bus注入到Vue ...
- mysqlslap基准测试
目录 简介 二.例子 三.其它选项 简介 mysqlslap是mysql自带的基准测试工具 优点:查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测 ...
- MySQL数据库如何查看数据文件的存放位置
SHOW GLOBAL VARIABLES;
- IOS 真机调试和发布相关证书
一.成员介绍1. Certification(证书)证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种:1) Developer Certification(开发证书)安装在电脑上 ...
- Linux 01 计算机硬件之冯诺依曼体系
1. 计算机硬件软件体系 1.1 冯诺依曼体系结构 (1) 计算机处理的数据和指令用二进制表示 (2) 按顺序执行指令 (3) 计算机硬件:运算器.控制器.储存器.输入设备和输出设备. 1.2 计算机 ...
- java 图形化小工具Abstract Window Toolit ;布局管理器FlowLayout流式布局;BorderLayout边界布局;GridLayout网格布局;CardLayou重叠卡片布局;BoxLayout方框布局;绝对定位
1.FlowLayout流式布局管理器: FlowLayout布局管理器中,组件像水流一样向某方向流动(排列),遇到障碍(边界)就折回,重头开始排列 .在默认情况下,FlowLayout局管理器从左向 ...
- Linux三剑客综合练习
1.找出/proc/meminfo文件中以s开头的行,至少用三种方式忽略大小写 [root@localhost ~]# grep -E '^[sS]' /proc/meminfo [root@loca ...
- linux 设备文件的操作
文件:包含数据,具有属性,通过目录中的名字被标识, 可以从文件读数据,可以向文件写数据. 设备也支持文件的操作. 每个设备都被当作一个文件,具有文件名,i-节点号,文件所有者,权限位的集合,最新修改时 ...