(Thirty) java version of spring cloud micro Services Architecture b2b2c e-commerce platform to build -commonservice-config configuration services

Spring Cloud is a cloud-based application development tool Spring Boot achieve, and it is cloud-based application development JVM involved in configuration management, service discovery, circuit breakers, intelligent routing, micro broker, a control bus, a global lock, decision-making campaign, distribution type and cluster session state management and other operations provides a simple way of development.

Spring Cloud contains a number of sub-projects (for distributed systems involved in a number of different open source products), such as: Spring Cloud Config, Spring Cloud Netflix, Spring Cloud0 CloudFoundry, Spring Cloud AWS, Spring Cloud Security, Spring Cloud Commons, Spring Cloud Zookeeper, Spring Cloud CLI and other projects.

Micro Services Architecture

"Micro Services Architecture" In the past few years is very hot, so that on the micro-architecture services related to open source products are repeatedly mentioned (for example: netflix, dubbo), Spring Cloud also due to strong visibility and impact of the Spring community is also the majority architects and developers concern.

So what is the "micro Services Architecture" mean? Simply put, micro Services Architecture is a complete application from the data storage start vertical split into multiple different services, each service can be deployed independently, separate maintenance, an independent extension, such as room service and service by the RESTful API way to call each other.

For the "micro Services Architecture", you can search the Internet to many research articles related to the introduction and to learn and understand. Ancestor may also read Martin Fowler's "Microservices" (Chinese version translated click to see), we do not do more introduction and description.

Service Management

After a brief introduction to Spring Cloud and micro-service architecture, following the return of the subject content of this article, how to use Spring Cloud to implement service governance.

Since the Spring Cloud made abstract interface layer service management, so in Spring Cloud applications can support many different services governance framework, such as: Netflix Eureka, Consul, Zookeeper. Under the influence of Spring Cloud service management abstraction layer, we can achieve seamless switching service governance, and does not affect any other service registration, service discovery, service calls and other logic.

So, let's appreciate the benefits of this layer of abstraction Spring Cloud brought realize introduce two service governance through.

Spring Cloud Eureka

First, let's try to use Spring Cloud Eureka to implement service governance.

Spring Cloud Eureka is a service management module in the Spring Cloud Netflix project. The project is one of Netflix Spring Cloud Spring Cloud subprojects, the main contents of the package is a series of open source products company Netflix, which offers Netflix OSS integration of self-configuration for Spring Boot application. With a few simple annotations, developers can quickly configure it in the application module and used to build large distributed systems. The main module include: service discovery (Eureka), circuit breaker (Hystrix), intelligent routing (Zuul), client load balancing (Ribbon) and so on.

Now, on to specifically look at how to use Spring Cloud Eureka implement service management.

Create a "service registry"

Creating a foundation of Spring Boot project, named eureka-server, and the introduction of content-dependent needed in pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
    <relativePath/>
</parent>

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

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

By @EnableEurekaServer annotations begin a dialogue to provide service registry to other applications. This step is very simple, just add this comment in an ordinary Spring Boot applications will be able to turn this feature on, as in the following example:

@EnableEurekaServer
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class)
                    .web(true).run(args);
    }
}

In the default setting, the service center will register itself as a client to attempt to register its own, so we need to disable its client registration behavior, only need to add the following information in application.properties configuration file:

spring.application.name=eureka-server
server.port=1001

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

In order to be registered with a subsequent service differentiation, where the service port by server.port property registry 1001. After starting the project, visit: http: / / localhost: 1001 /, you can see the following page, which also did not find any services.

Guess you like

Origin blog.csdn.net/vvx0206/article/details/93710697