Eureka - 服务注册和发现

2 篇文章 0 订阅
1 篇文章 0 订阅

 创建一个Eureka 是一个很简单的事,这点感谢Spring的一帮大神们,只需要写几个注解就OK了。

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServiceApplication.class, args);
    }
}

看到没,就这么简单 Eureka Server已经完成了。

不过测试的时候的注意一些事项。官网是这样说的:

    When the registry starts up it will complain, with a stacktrace, that there are no replica nodes for the registry to connect to. In a production environment, you will want more than one instance of the registry. For our simple purposes, however, it sufficies to disable the relevant logging.
    By default, the registry will also attempt to register itself, so you’ll need to disable that, as well.
It’s a good convention to put this registry on a separate port when using it locally.

    Add some properties to your eureka-service/src/main/resources/application.properties to handle all of these requirements.

  大致意思是说:当服务注册和发现服务启动后,他自己也会注册到,生产环境中我们的Eureka是多个,那没什么问题,开发坏境没必要启动多个实例,只需要启动一个,所以我们要在属性配置文件(application.properties)中做一些配置。

# 当前服务启动后的服务端口server.port=8761 #是否需要注册到注册中心,因为该项目本身作为服务注册中心,所以为false
eureka.client.register-with-eureka=false #是否需要从注册中心获取服务列表,原因同上,为false
eureka.client.fetch-registry=false

logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
下一章节 Eueark 客户端
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值