下面将 cloud-provider-payment8001 微服务注册到Eureka服务注册中心 cloud-eureka-server7001。
<br/>
步骤如下:
**1. 构建模块:cloud-provider-payment8001**
**2. 在 8001 模块的`pom.xml`中添加 eureka-client 与 actuator 依赖**
```xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<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>
...
</dependencies>
```
**3. 在 8001 模块的`resources/application.yml`中配置 eureka 相关**
```yml
server:
port: 8001
spring:
application:
name: cloud-payment-service
eureka:
client:
service-url:
#eureka提供的注册中心地址
defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/
instance:
#显示当前模块的名称
instance-id: ${project.artifactId}
#true:显示当前模块的ip地址
prefer-ip-address: true
lease-renewal-interval-in-seconds: 1
lease-expiration-duration-in-seconds: 2
####actuator####
info:
app.name: ${spring.application.name}
company.name: www.atguigu.com
build.artifactId: ${project.artifactId}
build.version: ${project.version}
```
**4. 在 8001 模块的启动类上添加注解`@EnableEurekaClient`**
```java
@SpringBootApplication
@EnableEurekaClient
public class PaymentMain8001 {
public static void main(String[] args) {
SpringApplication.run(PaymentMain8001.class,args);
}
}
```
**5. 验证**
(1)先启动 7001 Eureka服务注册中心,再启动 8001 模块。
(2)访问 7001 Eureka服务注册中心 http://www.eureka7001.com:7001/ ,显示如下图,可以看到已经有一个微服务注册进来了。
![](https://img.kancloud.cn/76/75/767558dba4f06f43224c5cf9805d0995_1608x177.jpg)
上图中的Application名字为 8001 模块中定义的名字,该名字非常重要,是该服务端向外提供服务时所使用的名字。
<br/>
:-: ![](https://img.kancloud.cn/78/fb/78fb238520c49b4f13020c5441650b2f_1473x367.jpg)
显示当前模块的ip地址
<br/>
![](https://img.kancloud.cn/e5/db/e5dbee4cdabe2cb4c167c52b3f9a7984_1681x162.jpg)
点击Status的微服务,便可以看到actuator的配置。
```json
{
"app":{
"name":"cloud-payment-service"
},
"company":{
"name":"www.atguigu.com"
},
"build":{
"artifactId":"cloud-provider-payment8001",
"version":"1.0-SNAPSHOT"
}
}
```
- 微服务
- 微服务是什么?
- 微服务架构
- 微服务优缺点
- 微服务技术栈
- 微服务框架对比
- SpringCloud
- SpringCloud是什么
- SpringCloud与SpringBoot对比
- SpringCloud与Dubbo对比
- Rest微服务案例
- 总体介绍
- 父工程构建步骤
- 公共模块构建步骤
- 服务端模块构建步骤
- 消费端模块构建步骤
- Eureka服务注册与发现
- Eureka是什么
- Eureka原理
- Eureka注册服务中心构建
- 向Eureka注册已有微服务
- Eureka的自我保护机制
- Eureka服务发现
- Eureka集群配置
- Eureka与Zookeeper对比
- Ribbon负载均衡
- Ribbon是什么
- Ribbon负载均衡演示
- 构建服务端模块
- 构建消费端模块
- Ribbon核心组件IRule
- 自定义负载均衡策略
- Ribbon均衡策略优先级
- 轮询策略算法
- OpenFeign负载均衡
- OpenFeign是什么
- 负载均衡演示
- 日志打印功能
- 导出功能
- Hystrix断路器
- Hystrix是什么
- 服务熔断
- Hystrix服务端构建
- 服务熔断演示
- 服务熔断类型
- HystrixProperty配置汇总
- 服务降级
- Hystrix客户端构建
- 服务降级演示
- fallbackFactory
- 熔断与降级
- 服务监控
- 网关服务Zuul
- Zuul是什么
- Zuul路由服务构建
- 设置访问映射规则
- Config分布式配置中心
- Config分布式配置中心是什么
- Config服务端与Git通信
- Config客户端获取配置
- Config客户端动态刷新
- Bus消息总线
- Bus消息总线是什么
- Bus消息总线原理
- 广播通知设计思想
- 广播通知演示
- 定点通知演示
- Stream消息驱动
- 为什么要引入Stream
- Stream消息驱动是什么
- Stream设计思想
- Stream流程和注解
- Stream案例演示
- 重复消费问题
- 消息持久化
- Sleuth分布式链路跟踪
- Sleuth是什么
- 搭建链路监控
- SpringCloud Alibaba
- Nacos注册与配置中心
- Nacos是什么
- 安装并运行Nacos
- Nacos注册中心
- 服务端入住Nacos
- 消费端入住Nacos
- Nacos负载均衡演示
- 服务注册中心对比
- Nacos的AP和CP转化
- Nacos配置中心
- 基础配置演示
- Nacos分类配置
- Nacos集群搭建
- Sentinel实现熔断与限流
- Sentinel是什么
- Sentinel环境搭建
- Sentinel监控微服务演示
- Sentinel流控规则
- 流量监控的作用
- 设置流控规则
- Sentinel降级规则
- 熔断降级作用
- 设置降级规则
- Sentinel热点限流
- 什么是热点
- 设置热点限流
- Sentinel系统限流
- @SentinelResource
- @SentinelResource属性
- @SentinelResource限流演示
- @SentinelResource熔断演示
- 规则持久化
- 熔断框架比较
- Seata分布式事务
- 分布式事务问题
- Seata是什么
- Seata分布式事务过程
- Seata环境搭建
- 演示示例
- 业务说明
- 数据库环境准备
- 微服务环境准备
- 测试
- Consul服务注册与发现
- Consul是什么
- Consul能做什么
- 环境搭建
- Windows平台
- 服务端入住Consul
- 消费端入住Consul
- 注册中心对比
- Zookeeper服务注册与发现
- Zookeeper是什么
- 环境搭建
- 服务端入住Zookeeper
- 消费端入住Zookeeper
- 网关服务Gateway
- Gateway是什么
- Gateway能做什么
- Gateway对比Zuul
- 三大核心概念
- Gateway工作流
- 环境搭建
- 网关路由配置方式
- 配置文件配置
- 代码中配置
- 动态路由
- Predicate断言
- 断言是什么
- 常用断言
- Filter过滤器
- 过滤器是什么
- 过滤器种类
- 自定义过滤器