[Eureka service registration discovery for microservices]

Service Discovery: Cloud Load Balancing, a REST-based service for locating services for load balancing in the cloud and failover of middle-tier servers.

1. The code is as follows

package com.didispace;

 

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.builder.SpringApplicationBuilder;

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

 

@EnableEurekaServer

@SpringBootApplication

public class Application {

 

public static void main(String[] args) {

new SpringApplicationBuilder(Application.class).web(true).run(args);

}

 

}

 

Remark:

@EnableEurekaServer //Open Eureka Server

@SpringBootApplication //springBoot annotation, spring builds the project on the basis of springBoot

 



 

 

Second, the configuration file details

server.port=1111

#eureka.instance.hostname=localhost

 

eureka.client.register-with-eureka=false

eureka.client.fetch-registry=false

eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

 

Here's an explanation:

server.port --- > port where the service is started

spring.application.name ---> This is a service name. When configuring high availability and other services to access the service, it is through this property to find the service registry to obtain the available access ip (of course, you can directly call other services through ip , then don't use sc

eureka.client.serviceUrl.defaultZone - --> This is the address of service registration. Later, when it comes to the high availability service registration center, you will see that multiple addresses of this attribute are separated by commas

 

3. Result verification


 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326082953&siteId=291194637