Building a microservices Architecture Spring Cloud: Service registration and Discovery (Eureka, Consul)

Source: Internet
Author: User
Tags zookeeper

About Spring Cloud

Spring Cloud is a spring boot-based cloud application development tool for configuration management, service discovery, circuit breakers, intelligent routing, micro-agents, control buses, global locks, decision-making campaigns, Operations such as distributed sessions and cluster state management provide a simple way to develop.

Spring Cloud contains multiple sub-projects (for many different open source products involved in distributed systems), 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 more.
Micro-Service Architecture

The "MicroServices architecture" has been so hot these past few years that the open source products related to MicroServices architectures have been repeatedly mentioned (e.g. Netflix, Dubbo), and Spring cloud has been the focus of architects and developers for the strong visibility and influence of the spring community.

So what is a "microservices architecture"? To put it simply, a microservices architecture is to split a complete application from the data store vertically into multiple different services, each of which can be deployed independently, independently maintained, independently scaled, and invoked between services and services through, for example, restful APIs.

For the "micro-service Architecture", we can find a lot of relevant introduction and research articles on the Internet to learn and understand. You can also read the ancestor Martin Fowler's "MicroServices" (Chinese version of translation Click to view), this article does not do more introduction and description.
Service governance

After a brief introduction to Spring cloud and the microservices architecture, here's what the main thrust of this article is, and how to use spring Cloud for service governance.

Because spring Cloud provides a layer of abstraction for service governance, there are a number of different service governance frameworks that can be supported in spring cloud applications, such as Netflix Eureka, Consul, and Zookeeper. With the Spring cloud service Governance Abstraction layer, we can seamlessly switch service governance implementations without affecting any other logic such as service registration, service discovery, service invocation, and so on.

So, let's introduce the benefits of the abstraction from spring cloud by introducing two implementations of service governance.
Spring Cloud Eureka

First, let's try using spring Cloud Eureka to implement service governance.

Spring Cloud Eureka is the Service governance module under the spring Cloud Netflix project. The spring cloud Netflix project is one of Spring cloud's sub-projects, primarily packaged with Netflix's range of open source products, which provides a self-configuring Netflix OSS integration for spring boot applications. With some simple annotations, developers can quickly configure common modules in the application and build large, distributed systems. It mainly provides modules including: Service Discovery (Eureka), Circuit breakers (Hystrix), intelligent routing (Zuul), Client load Balancing (Ribbon), etc.

Here's a look at how to implement service governance with spring Cloud Eureka.
Create a Service registration center

Create a basic spring boot project, named Eureka-server, and introduce the required dependencies in the 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.springframewo Rk.cloud</groupid> <artifactId>spring-cloud-dependencies</artifactId> <version> ;D Alston. sr1</version> <type>pom</type> <scope>import</scope> </depende Ncy> </dependencies></dependencymanagement>  

Start a service registry with @enableeurekaserver annotations to provide conversations to other apps. This step is very simple, just add this annotation to a normal spring boot application to enable this feature, such as the following example:

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

By default, the service registry will also attempt to register itself as a client, so we need to disable its client registration behavior by simply adding the following information to the Application.properties configuration file:

spring.application.name=eureka-serverserver.port=1001eureka.instance.hostname=localhosteureka.client.register-with-eureka=falseeureka.client.fetch-registry=false

The schema code is as follows:

Building a microservices Architecture Spring Cloud: Service registration and Discovery (Eureka, Consul)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.