欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

微服务架构-eureka

程序员文章站 2024-03-20 22:14:58
...

pom文件

<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>
    <parent>
        <groupId>com.cloud.logistics</groupId>
        <artifactId>cloudlogistics</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>cloud-logistics-eureka</artifactId>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                </configuration>
            </plugin>
        </plugins>

    </build>
</project>

在main方法上添加:

@EnableEurekaServer
@SpringBootApplication
public class CloudLogisticsEurekaApp {

	public static void main(String[] args) {

		SpringApplication.run(CloudLogisticsEurekaApp.class, args);
	}
}

application.yml:

server:
  port: 8761
spring:
  profiles:
    active: dev
  application:
    name: cloud-logistics-eureka
eureka:
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
  server:
    enable-self-preservation: false # 自我保护关闭, 利于测试
    eviction-interval-timer-in-ms: 5000 #清理间隔
info:
  app:
    name: ${spring.application.name}
    company:
      name: cloud

application-dev.yml

server:
  port: 8761
eureka:
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
  client:
    register-with-eureka: true  #false:不作为一个客户端注册到注册中心
    fetch-registry: false # 单机模式下 不行集群同步
    serviceUrl:
      defaultZone: http://${spring.cloud.client.ip-address}:${server.port}/eureka/
  server:
    enable-self-preservation: false # 自我保护关闭, 利于测试
    eviction-interval-timer-in-ms: 5000 #清理间隔

application-prod.yml:

server:
  port: 8761
eureka:
  client:
    register-with-eureka: true  #false:不作为一个客户端注册到注册中心
    fetch-registry: true # 单机模式下 不行集群同步
    serviceUrl:
      defaultZone: http://192.168.104.96:${server.port}/eureka/,http://192.168.104.97:${server.port}/eureka/