Eureka service and client

    Eureka is a service discovery framework developed by Netflix, SpringCloud to integrate it in their own subprojects
spring-cloud-netflix, the realization SpringCloud service discovery. Eureka consists of two components:
Eureka Server and Eureka Client.
     Eureka Server service registration services, after each node starts, the note in Eureka Server in the
book, such EurekaServer in the service registry will store information about all the available service node, the service node
information can be intuitively see in the interface to.
Java Eureka Client is a client for interacting with the simplified Eureka Server, the client also
do not built a, polling (round-robin) load load balancing algorithm. After the application starts, it will
send to Eureka Server heartbeat, the default period is 30 seconds, if not in a more Eureka Server heartbeat period
received a node heartbeat, Eureka Server service from the registry will put the service node remove (default 100
seconds).
     Between Eureka Server synchronization is accomplished by way of copying data, Eureka also provides the client cache machine
system, even if all of Eureka Server will hang up, the client still can use the information in the cache consumption of other services
API. In summary, the Eureka heartbeat checking, client caching mechanisms to ensure high system availability, flexibility
and scalability.

1. server

Creating micro server service

Parent Project management depends version

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

 

Micro Engineering Services

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
    </dependencies>
Server: 
  Port: 6868 # port services 
Eureka: 
  Client: 
    the Register the -with-Eureka: false # whether to register itself to Eureka, do not need 
    FETCH -registry: false # whether to obtain registration information from Eureka in 
    Service - url: 
      defautZone: HTTP : // 127.0.0.1:${server.port}/eureka/

 

@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServer.class);
    }
}

2. Client

Clients rely

Add the startup class notes:

@EnableEurekaClient
  <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

 

 

Eureka: 
  Client: 
    Service - url: 
      defaultzone: HTTP: // localhost: 6868 / Eureka 
      instance: 
        the prefer-ip-address:  to true # cross-domain access

 

Guess you like

Origin www.cnblogs.com/liushisaonian/p/11258678.html