java version of spring cloud+spring boot social e-commerce platform Eureka (Service Registration and Service Discovery Foundation)

1: Introduction to Eureka
Eureka is a sub-module and one of the core modules of Spring Cloud Netflix.For Cloud Service Discovery, a REST-based service for locating services for cloud mid-tier service discovery and failover.Java springcloud B2B2C o2o multi-user shop springcloud architecture

Service registration and discovery are important for micro-service systems.With service discovery and registration, you don't have to change the configuration file for service calls all day long. You only need to use the service's identifier to access the service.It functions like the dubbo registration center.

Service discovery: Service discovery is one of the key principles of the microservice infrastructure.Trying to start configuring the conventions for each client or format can be difficult and fragile.Eureka is a service and client discovered by Netflix services.Such services can be configured and deployed with high availability, and in registered services, the state of each service can be replicated to each other.

Service registration: When a client is registered with Eureka, it provides metadata about itself (such as host and port, health metrics URL, home page, etc.) Eureka receives heartbeat information from each instance through a service.If a heartbeat receive fails longer than the configured time, the instance will be removed from the registration normally

2: 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);
   }
  
 }

Start a service registry with the @EnableEurekaServer annotation to provide dialogs to other applications.

3: Create a configuration file application.properties, be careful not to have spaces or start errors

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

4: Execute bluid.sh to build, then execute the main method.Since I did not compile manually under eclipse, I could not read application.properties at startup.
Isn't it very simple? Then people should ask why they don't even have a login account and password and can't directly enter the registration center on the outside net. It's so insecure.Okay, let's add the login account and password


Keywords: Delphi Spring Maven Java Apache

Added by fenway on Tue, 30 Jul 2019 04:46:50 +0300