Spring Cloud Eureka可以作为微服务的服务注册和发现中心。Spring Cloud还支持其他方式的注册和发现中心比如Spring Cloud Zookeeper和Consul,etcd等
先完成 Zookeeper的Windows集群搭建,接下来要做的是搭建基于Zookeeper集群的微服务的注册和调用。其中使用Feign进行负载均衡。

项目结构

外层pom配置文件,如果下图中配置文件中引入的zookeeper包是
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zookeeper-all</artifactId>
</dependency>可能项目启动的时候报错
java.lang.reflect.UndeclaredThrowableException: null
	at org.springframework.util.ReflectionUtils.rethrowRuntimeException(ReflectionUtils.java:152) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry.register(ZookeeperServiceRegistry.java:74) ~[spring-cloud-zookeeper-discovery-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry.register(ZookeeperServiceRegistry.java:40) ~[spring-cloud-zookeeper-discovery-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) ~[spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cloud.zookeeper.serviceregistry.ZookeeperAutoServiceRegistration.register(ZookeeperAutoServiceRegistration.java:78) ~[spring-cloud-zookeeper-discovery-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) ~[spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) ~[spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) ~[spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) ~[spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplicatio
 
                   
                   
                   
                   本文介绍了如何在Spring Cloud项目中使用Zookeeper作为服务注册和发现中心,详细阐述了Zookeeper集群的Windows搭建过程,以及如何在微服务中配置Zookeeper,使用Feign实现负载均衡。在配置过程中,提到了可能遇到的问题和解决方案,并提供了完整的项目结构、配置文件和源代码链接。
本文介绍了如何在Spring Cloud项目中使用Zookeeper作为服务注册和发现中心,详细阐述了Zookeeper集群的Windows搭建过程,以及如何在微服务中配置Zookeeper,使用Feign实现负载均衡。在配置过程中,提到了可能遇到的问题和解决方案,并提供了完整的项目结构、配置文件和源代码链接。
           最低0.47元/天 解锁文章
最低0.47元/天 解锁文章
                           
                       
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   2932
					2932
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            