SpringCloud of Eureka

First, the first to build a registry as Eureka Server
1. introducing dependent
<! - Add eureka server ->
<dependency>
<the groupId> org.springframework.cloud </ the groupId>
<the artifactId> Spring-Cloud-starter- Eureka-Server-Netflix </ artifactId>
</ dependency>
2. write configuration
as a registration center, the port number is 8001, service-eureka service name used

# Configure the port number
Server:
Port: 8001

# service name
the Spring:
the Application:
name: Service-eureka
this eureka configuration purpose is to add a service to the registry to
register the address is: http: // localhost: 8001 / eureka /

#eureka configuration
Eureka:
Client:
# is not registered with the service registry
# the Register-with-Eureka: false
FETCH-Registry: false
Service-url:
defaultzone: HTTP: // localhost: 8001 / Eureka /
Server:
# active time to failure
--the Timer-interval The eviction in MS-: 30000
Registry-Sync-retry-the wait-MS: 500
ASG-Cache-expiry-timeout-MS: 60000
the peer-Eureka-Nodes-Update-interval The MS-: of 15,000
Renewal-threshold- MS-interval the-Update: 300000
# test environment close limp home mode
#-enable self-Preservation: false
3. start to add annotations
to add @EnableEurekaServer start the registration centers
because there is no such thing as a database registry, so start being given back @SpringBootApplication Add
exclude = {DataSourceAutoConfiguration.class} 

@EnableEurekaServer
@SpringBootApplication (DataSourceAutoConfiguration.class the exclude = {})
public class EurekaApplication {
public static void main (String [] args) {
SpringApplication.run (EurekaApplication.class, args);
}
}
4. Start the registry and to access
the access path : localhost: 8001


Here you can see service-eureka as a service registry to registry in the

Second, write a service registered as a client to the registry Eureka
1. introducing dependent
<-! Add eureka client ->
<dependency>
<groupId> org.springframework.cloud </ groupId>
<artifactId> the Spring-Cloud -Netflix-Eureka--starter Client </ artifactId>
</ dependency>
2. write configuration
micro service port number is 8084, service-admin service name used

# Configure the port number
Server:
Port: 8084

# service name
the Spring:
the Application:
name: Service-ADMIN
still add service to the registry to
register the address remains: http: // localhost: 8001 / eureka /

#eureka configuration
Eureka:
Client:
Service-url:
defaultzone: HTTP: // localhost: 8001 / Eureka /
# How many seconds interval to the server got me Registration Information
Registry-FETCH-seconds The interval The-: 10
instance:
# Send heartbeat to server end frequency
Lease-Renewal-in-seconds The interval The-: 30
# address health check
health-the check-url-path: / Actuator / health
the prefer-ip-address: to true
3. start to add annotations
@EnableEurekaClient notes is based on the spring-cloud -netflix rely only eureka use
@EnableDiscoveryClient notes is based on the spring-cloud-commons-dependent, and is implemented in the classpath
their role is the same, so I chose @EnableDiscoveryClient
add @EnableDiscoveryClient will be registered as a client to the service registry

@EnableDiscoveryClient
@SpringBootApplication
public class AdminApplication {
public static void main (String [] args) {
SpringApplication.run (AdminApplication.class, args);
}
}
4. Start the registry and to access
the access path: localhost: 8001
----- ----------------

Guess you like

Origin www.cnblogs.com/hyhy904/p/11106088.html