既然用到微服务,服务的注册和发现应该可以算作是微服务的核心了吧。使用过dubbo的人,应该都知道dubbo的服务注册和发现中心是通过zookeeper来提供的。Eureka 是 Netflix 开源的服务注册发现组件,当然也可以提供类似的功能。
启动类:EurekaServerApplication
package com.cn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
配置文件:application.yml
server:
port: 8080
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
enable-self-preservation: false
instance:
hostname: