码迷,mamicode.com
首页 > 其他好文 > 详细

服务注册与发现

时间:2019-01-17 13:56:30      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:client   inter   group   情况   log   缓存   依赖   load   分享   

Spring Cloud使用演示版本

Edgware.SR5版本,Spring Cloud 1.xxx版本。如果使用Spring Cloud 2.xxx版本,请注意有些依赖的变化。从Finchley版本之后,进入Spring Cloud 2.xxx。

[Spring Cloud 管理依赖链接](https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies )

概述

需要用到组件是Spring Cloud Netflix的Eureka,Eureka是一个服务注册与发现模块

创建服务注册中心

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>            

启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
?
/**
* Eureka registry center application
**/
@EnableEurekaServer
@SpringBootApplication
public class EurekaRegistryApplication {
?
   public static void main(String[] args) {
       SpringApplication.run(EurekaRegistryApplication.class, args);
  }
}

application.yml

Eureka 是一个高可用的组件,它没有后端缓存,每一个实例注册之后需要向注册中心发送心跳(因此可以在内存中完成),在默认情况下 Erureka Server 也是一个 Eureka Client ,必须要指定一个 Server。


server:
port: 1111
?
?
eureka:
server:
  enable-self-preservation: false #关闭保护机制
  eviction-interval-timer-in-ms: 3000 #剔除失效服务间隔(默认60s)
instance:
  hostname: localhost
client:
  register-with-eureka: false #该应用是注册中心,代表不向注册中心注册自己
  fetch-registry: false #由于注册中心职责是维护服务实例,它并不需要检索服务
  serviceUrl:
    defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  healthcheck:
    enabled: true
?
?
spring:
application:
  name: eureka-registry
?

操作界面

Eureka Server是有界面,启动工程,访问:http://localhost:1111

技术分享图片

服务注册与发现

标签:client   inter   group   情况   log   缓存   依赖   load   分享   

原文地址:https://www.cnblogs.com/liuenyuan1996/p/10281602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!