Eureka服务-提供-消费

父类模块

在父类pom文件中指定版本依赖<dependencyManagement> 

 <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.1.5.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

EurekaServier模块

在本模块中添加eureka依赖,jar

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

 

编写注册中心

## 启动顺序: #1
spring.application.name=eureka-server
server.port=20000

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
//拉取出册表
eureka.client.fetch-registry=false

 

启动类 

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        new SpringApplicationBuilder(EurekaServerApplication.class)
                .web(WebApplicationType.SERVLET)
                .run(args);
    }
}

build 


        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.imooc.EurekaServerApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

 

EurekaUI

Renews threshold:每分钟最少的续约数量

Renews:上一分钟的续约数

 

EurekaClient模块(提供者)

在本模块中添加eureka依赖,jar

  <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-web</artifactId>
        </dependency>
    </dependencies>

启动类 

@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientApplication {
    public static void main(String[] args) {
        new SpringApplicationBuilder(EurekaClientApplication.class)
                .web(WebApplicationType.SERVLET)
                .run(args);
    
    }
}

编写注册 

spring.application.name=eureka-client
server.port=30000
eureka.client.serviceUrl.defaultZone=http://localhost:20000/eureka/

EurekaConsumer模块(消费者)

在本模块中添加eureka依赖,jar

 <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-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

配置文件 

spring.application.name=eureka-consumer
server.port=40000
eureka.client.serviceUrl.defaultZone=http://localhost:20000/eureka/

 

开启心跳健康检查

注册端

#每隔5秒钟中,向服务中心发送一条续约指令
eureka.instance.lease-renewal-interval-in-seconds= 5
#如果30秒内,依然没有收到续约请求,判定服务过期(上西天)
eureka.instance.lease-expiration-duration-in-seconds= 30

服务端 


#强制关闭服务自保
eureka.server.enable-self-preservation=false
#每隔多久触发服务剔除 1秒
eureka.server.eviction-interval-timer-in-ms=10000

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值