Build a micro-service registration center based on Spring Cloud _spring

Source: Internet
Author: User
In a few simple steps, build a micro service registry based on spring cloud, including several features:
-Provide registration center to be registered by service provider
-Service consumer finds the service location in the registry
-High Availability (cluster) configuration

1, the introduction of dependence:
Two dependencies need to be introduced:
	<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>Camden.SR2</version>
				<type>pom</type>
				<scope >import</scope>
			</dependency>
		</dependencies>
	</dependencymanagement >

2. Configuration:
In order to configure a highly available registry cluster, 3 registries are configured to spare each other. Assume that the host is:
-192.168.0.9
-192.168.0.10
-192.168.0.18

Port is 58000.
Spring:
  Profiles:
    active:dev
  application:
    name:eureka-service
    
server:
  port:58000
Management:
  port:59000

Eureka:
  client:
    #register-with-eureka:false
    fetch-registry:false
  #instance:
  #  Prefer-ip-address:true
        
---
# development environment Configuration
Spring:
  profiles:dev

---
# Development Service 0 Configuration
Spring:
  profiles:dev0

Eureka:
  instance:
    hostname:192.168.0.9
  Client:
    service-url:
      defaultzone:http://192.168.0.10:58000/eureka/,http://192.168.0.18:58000/eureka/

---
# Development Service 1 Configuration
spring:
  profiles:dev1

Eureka:
  instance:
    hostname:192.168.0.10
  client:
    service-url:
      defaultzone:http://192.168.0.9:58000/eureka/,http://192.168.0.18:58000/ eureka/

---
# Development Service 2 configuration
Spring:
  profiles:dev2

Eureka:
  instance:
    hostname: 192.168.0.18
  Client:
    service-url:
      defaultzone:http://192.168.0.10:58000/eureka/,http:// 192.168.0.9:58000/eureka/

3, Code:
Just one main class is all you need:
@EnableEurekaServer
@SpringBootApplication Public
class Registryapplication {public

	static void main ( String[] args) {
		springapplication.run (registryapplication.class, args);
	}
}

4. Deployment and Inspection results:
Deploy three service centers to three servers, and then open the Administration page:
Http://192.168.0.9:58000/

You can see if the individual standby (replicas) registry is available if it has started normally.


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.