java version of spring cloud + spring boot social e-commerce platform (two) Eureka (service registration and service discovery Basics)

A: Eureka Description
Eureka Spring Cloud Netflix is a sub-module, it is also one of the core modules. Drive for service discovery, a REST-based services, for location services, the intermediate layer in order to achieve the cloud service discovery and failover. Java springcloud B2B2C o2o multi-user architecture Mall springcloud

Service registration and discovery is very important for micro-service systems. With service discovery and registration, you do not need to change the day of the service call configuration file, you only need to use the service identifiers, you can access to the service. His function is similar to the registration center dubbo (register).

Service Discovery: Service discovery is one of the key principles of micro-services infrastructure. Trying to proceed to configure each client or some form of agreement can be said to be very difficult and very fragile. Eureka is the discovery of a service Netflix service and client. Such services can be configured for high availability and deployment, and among the registered service, the status of each service may be replicated to each other.

Service Registration: When a client registers to Eureka, which provides on its own metadata (such as host and port health indicators URL, home, etc.) Eureka receive a heartbeat message from a service by each instance. If it fails to receive a heartbeat longer than the configured, examples of which will normally be removed from the register

Two: Eureka service discovery and registration (create registry)

<?xml version="1.0" encoding="UTF-8"?>
    <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>
        <groupId>com.demo.springcloud</groupId>
        <artifactId>eureka_register_service</artifactId>
        <version>1.0.0</version>
        <packaging>jar</packaging>
        <name>eureka_register_service</name>
        <description>Spring Cloud project</description>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.3.RELEASE</version>
            <relativePath />
        </parent>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka-server</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
        </dependencies>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>Brixton.RELEASE</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>   

2: Create a startup class Application

package com.demo.springcloud;
  
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
  
 @EnableEurekaServer
 @SpringBootApplication
 public class Application {
   public static void main(String[] args) {
       SpringApplication.run(Application.class, args);
   }
  
 }

By @EnableEurekaServer annotations begin a dialogue to provide service registry to other applications.

3: Create a profile application.properties, be careful not to use spaces, whether to start the error

server.port=8000
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

4: performing bluid.sh constructed, and then execute the main method. Since I did not manually compile in eclipse, the start time has not read application.properties.
Is not very simple ah, then people have to ask, why even the login ID and password are not, the external network can not directly access the registration center, so very safe ah. Well, then we join login ID and password
Spring cloud b2b2c social e-commerce platform source code, please add penguin beg: three four five three six II qi II fifty-nine

Guess you like

Origin blog.csdn.net/qq_42748864/article/details/93462328