Spring Cloud
  • Introduction
  • 网站架构演变过程
    • 微服务架构
  • Spring Cloud 简介
  • 服务的注册与发现
    • 其他知识
      • Zookeeper与Eureka区别
      • DiscoveryClient 与@EnableEurekaServer
    • Zookeeper
    • Consul
    • Eureka
      • 搭建注册中心
      • 高可用注册中心
      • Eureka详解
  • 服务消费者
    • RestTemplate
    • 服务消费者(rest+ribbon)
      • 此时架构
    • 服务消费者(Feign)
  • 断路器(Hystrix)
    • 基础入门
  • API Gateway(Zuul)
    • 基础入门
  • 分布式配置中心(Config)
    • 基础入门
  • SpringCloud Bus
  • 链路跟踪(Sleuth)
  • 数据流(Stream)
  • Dubbo
    • Untitled
Powered by GitBook
On this page
  • DiscoveryClient用法
  • @EnableDiscoveryClient 与@EnableEurekaClient区别

Was this helpful?

  1. 服务的注册与发现
  2. 其他知识

DiscoveryClient 与@EnableEurekaServer

DiscoveryClient用法

discoveryClient接口 可以获取注册中心上的实例信息。

@EnableDiscoveryClient 开启其他注册中心 比如consul、zookeeper

@SpringBootApplication
@EnableDiscoveryClient
public class AppMember {
	public static void main(String[] args) {
		SpringApplication.run(AppMember.class, args);
	}
}

获取注册中心上信息

@RequestMapping("/getServiceUrl")
	public List<String> getServiceUrl() {
		List<ServiceInstance> list = discoveryClient.getInstances("zk-member");
		List<String> services = new ArrayList<>();
		for (ServiceInstance serviceInstance : list) {
			if (serviceInstance != null) {
				services.add(serviceInstance.getUri().toString());
			}
		}
		return services;
	}

@EnableDiscoveryClient 与@EnableEurekaClient区别

1,@EnableDiscoveryClient注解是基于spring-cloud-commons依赖,并且在classpath中实现; 适合于consul、zookeeper注册中心

2,@EnableEurekaClient注解是基于spring-cloud-netflix依赖,只能为eureka作用;

PreviousZookeeper与Eureka区别NextZookeeper

Last updated 4 years ago

Was this helpful?