dubbo和zikkeper的使用


1、先來一段異常看看:No provider available for the service

16:05:25.755 [localhost-startStop-1] WARN o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartz': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.rpc.OrgRPC com.xinping.crm.until.taglib.Quartz.orgRPC; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orgRPC': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.test.rpc.OrgRPC. No provider available for the service com.test.rpc.OrgRPC from the url zookeeper://zookeeper-ip:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=TEST_CRMWH_HELPER&check=false&dubbo=2.5.3&generic=false&interface=com.test.rpc.OrgRPC&methods=getOrgListByIdOrParentIdOrUpdateTime,getOrgById&pid=7916&revision=1.0.1-api&side=consumer&timeout=60000&timestamp=1471853122008 to the consumer consumer-ip use dubbo version 2.5.3 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016) [catalina.jar:7.0.61] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528) [catalina.jar:7.0.61] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.61] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575) [catalina.jar:7.0.61] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) [catalina.jar:7.0.61] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79] Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.rpc.OrgRPC com.xinping.crm.until.taglib.Quartz.orgRPC; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orgRPC': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.test.rpc.OrgRPC. No provider available for the service com.test.rpc.OrgRPC from the url zookeeper://zookeeper-ip:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=TEST_CRMWH_HELPER&check=false&dubbo=2.5.3&generic=false&interface=com.test.rpc.OrgRPC&methods=getOrgListByIdOrParentIdOrUpdateTime,getOrgById&pid=7916&revision=1.0.1-api&side=consumer&timeout=60000&timestamp=1471853122008 to the consumer consumer-ip use dubbo version 2.5.3 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:558) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] ... 22 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orgRPC': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.test.rpc.OrgRPC. No provider available for the service com.test.rpc.OrgRPC from the url zookeeper://zookeeper-ip:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=TEST_CRMWH_HELPER&check=false&dubbo=2.5.3&generic=false&interface=com.test.rpc.OrgRPC&methods=getOrgListByIdOrParentIdOrUpdateTime,getOrgById&pid=7916&revision=1.0.1-api&side=consumer&timeout=60000&timestamp=1471853122008 to the consumer consumer-ip use dubbo version 2.5.3 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1506) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:250) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:530) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] ... 24 common frames omitted Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.test.rpc.OrgRPC. No provider available for the service com.test.rpc.OrgRPC from the url zookeeper://zookeeper-ip:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=TEST_CRMWH_HELPER&check=false&dubbo=2.5.3&generic=false&interface=com.test.rpc.OrgRPC&methods=getOrgListByIdOrParentIdOrUpdateTime,getOrgById&pid=7916&revision=1.0.1-api&side=consumer&timeout=60000&timestamp=1471853122008 to the consumer consumer-ip use dubbo version 2.5.3 at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:420) ~[dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300) ~[dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138) ~[dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65) ~[dubbo-2.5.3.jar:2.5.3] at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] ... 32 common frames omitted 16:05:25.755 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed 八月 22, 2016 4:05:25 下午 org.apache.catalina.core.StandardContext startInternal 嚴重: Error listenerStart 八月 22, 2016 4:05:25 下午 org.apache.catalina.core.StandardContext startInternal 嚴重: Context [/crm] startup failed due to previous errors 八月 22, 2016 4:05:25 下午 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55

異常分析: 

上面的異常,Caused by的前半部分有的說bean創建失敗,有的說屬性自動裝配失敗,但后半部分都比較統一,都是:No provider available for the service ……,服務沒有可以使用的提供者,完整意思就是:對於消費者(consumer-ip)而言,在zookeeper注冊中心(zookeeper-url)沒有可用的提供者(No provider available for the service com.test.rpc.OrgRPC),消費者訪問提供者的時候失敗了; 

因為消費者沒有變,變化的是向注冊中心注冊的提供者由開發服務器變更為測試服務器,同時由於之前處理過因為【No route to host】引起的異常,所以想到可能是提供者端口不通造成的,然后從消費者服務器telnet 提供者ip 20880端口,果然如此。

解決辦法: 

將提供者服務器的20880端口開放給消費者服務器ip,重新啟動消費者服務器,正常啟動。

2、dubbo+zookeeper與提供者provider、消費者consumer之間通信過程

先說一下整個系統框架的基本構造:

  • zookeeper作為注冊中心,使用單獨服務器,占用2181端口

  • dubbo-admin作為監控中心,與zookeeper使用相同服務器,tomcat部署占用8080端口

  • provider作為提供者,使用單獨服務器,tomcat部署占用8080端口,使用dubbo協議開放20880端口

  • consumer作為消費者,使用單獨服務器,tomcat部署占用8080端口

再看上面的異常,雖然解決了,是不是有人和我一樣有一些問題想不通:

  • provider服務器端口是8080,為什么telnet測試以及解決方案中開放的端口卻是20880?

  • 要說dubbo協議開放了20880端口,那8080端口應該也開放啊?

  • zookeeper、provider、consumer之間端口開放和屏蔽情況到底是怎么回事?

帶着這些問題,進行了相關的驗證,最終得出如下結論,先看圖,再解釋:

這里寫圖片描述

 

1)、用dubbo協議在20880端口暴露服務

 


在提供者的dubbo配置文件中,一般都配置了<dubbo:protocol name="dubbo" port="20880"/>,表明用dubbo協議在20880端口暴露服務,當然如果你不配置,dubbo默認使用20880端口暴露服務,所有消費者都是通過20880端口進行,對於消費者而言,提供者服務器8080端口是透明的,也就是說提供者服務器端口號可以任意改變,服務也不會有任何影響,消費者無需關心。 

所以上面的異常解決辦法是開放20880端口給消費者,而不是8080端口給消費者。

從監控中心可以看到如圖:

這里寫圖片描述

除了在指定端口上暴露服務之外,還可以在指定ip上暴露服務,配置如下:

<dubbo:protocol name="dubbo" host="10.1.22.2" port="20880" />
  • 1

 

2)、端口開放情況

 

zookeeper作為注冊中心,provider注冊服務、consumer訂閱服務、dubbo-admin監控服務,所以zookeeper注冊中心的2181端口需要向provider、consumer、dubbo-admin開放;

一般情況下,dubbo-admin監控中心與zookeeper注冊中心部署在相同的服務器上,zookeeper可以不考慮端口開放給dubbo-admin的情況;

consumer訂閱服務,即拿到了provider在20880端口暴露的服務,當consumer請求服務時,直接從consumer跳到provider,而不是consumer到zookeeper再到provider,所以provider的20880無需開放給zookeeper;

同理,provider響應服務時,也是直接從provider到consumer,而不是provider到zookeeper再到consumer,所以consumer的8080無需開放給zookeeper;

zookeeper注冊中心是完全被動的。


總結一下: 

- zookeeper的2181開放給provider、consumer、dubbo-admin 

- provider的20880開放給所有consumer,但8080服務器端口可以完全屏蔽 

- consumer的8080開放給所有provider 

- dubbo-admin的8080開放給管理員用戶,便於通過瀏覽器監控注冊中心服務的情況 

- 總結:注冊中心只負責服務注冊和目錄發布,安全授權,實際的服務訪問仍然是兩個組件之間的點對點連接完成,這種方式下整個架構下獲取更高的性能,同時服務管理平台也不容易成為大並發服務訪問下的單點瓶頸


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM