zoukankan      html  css  js  c++  java
  • 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开放给管理员用户,便于通过浏览器监控注册中心服务的情况 

    - 总结:注册中心只负责服务注册和目录发布,安全授权,实际的服务访问仍然是两个组件之间的点对点连接完成,这种方式下整个架构下获取更高的性能,同时服务管理平台也不容易成为大并发服务访问下的单点瓶颈

  • 相关阅读:
    Phantomjs 一些简单实用
    JAVA中关于数组的定义
    itextpdf JAVA 输出PDF文档
    MyBatis在insert插入操作时返回主键ID的配置
    卫士通加密机 控制台终端管理程序
    通过DOS、SHELL批处理命令加载Lib并编译和打包Java项目(或者运行项目)
    HTML单选按钮样式更换
    JAVA生成图片缩略图、JAVA截取图片局部内容
    JAVA笔记 之 Thread线程
    JAVA笔记 之 JDK新特性
  • 原文地址:https://www.cnblogs.com/xyzq/p/7490055.html
Copyright © 2011-2022 走看看