dubbo框架的优化

1.超时问题
这里写图片描述
1、服务消费方通过注册中心获取服务提供方的地址、调用服务提供方、由于服务提供方可能已经宕机、不能提供服务
2、服务消费方在1秒内没有得到回应、为了给用户提供非常服务、马上与服务提供方断开连接、再向注册中心获取新的服务提供方的地址、调用新的服务提供方
3.Dubbo用此方法来完成分布式情况下、服务器出现故障、而不影响用户的访问

解决方法:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo        
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 服务消费方 -->
    <!-- 1:此服务启个名称 -->
    <dubbo:application name="shopping-web-console"/>
    <!-- 2:连接zookeeper  redis -->
    <dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/>
    <!-- 3:配置 获取 接口 -->
    <dubbo:reference interface="open.shopping.service.TestUserService" id="testUserServiceImpl" />

    <!--全局设置超时时间   10分钟,默认是1秒-->
    <dubbo:consumer timeout="600000"/>

</beans>

2.连接问题
dubbo服务提供方和服务消费方都要通过注册中心提供服务与消费服务,注册中心zookeeper通常在遥远的机房,这个在开发中是极其不便利的。所以,我们在开发中一般将dubbo改用为直接连接。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo        
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 服务消费方 -->
    <!-- 1:此服务启个名称 -->
    <dubbo:application name="shopping-web-console"/>
    <!-- 2:连接zookeeper  redis -->
    <!-- <dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/> -->
    <dubbo:registry address="N/A"/>
    <!-- 3:配置 获取 接口 -->
    <dubbo:reference interface="open.shopping.service.TestUserService" id="testUserServiceImpl" />

    <!--全局设置超时时间   10分钟,默认是1秒-->
    <dubbo:consumer timeout="600000"/>

</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo        
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 服务提供方 -->
    <!-- 1:此服务启个名称 -->
    <dubbo:application name="shopping-service-product" />
    <!-- 2:连接zookeeper  redis -->
    <!-- <dubbo:registry address="192.168.9.129:2181" protocol="zookeeper" /> -->
    <dubbo:registry address="N/A"/>
    <!-- 3:配置暴露给注册中心的 ip  port  默认20880 -->
    <dubbo:provider host="127.0.0.1" port="20880" />
    <!-- 4:配置暴露 接口 -->
    <dubbo:service interface="open.shopping.service.TestUserService" ref="testUserServiceImpl" />

</beans>

3.检查问题
现在启动服务消费方,会报

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'testSpringMvcController': Injection of autowired dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private 
open.shopping.service.TestUserService open.shopping.test.testSpringMvcController.testUserService; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'testUserService': FactoryBean threw exception on object creation; nested exception is 
com.alibaba.dubbo.rpc.RpcException: Fail to create remoting client for service(dubbo://127.0.0.1:20880
/open.shopping.service.TestUserService?application=shopping-web-console&codec=dubbo&default.timeout=60
0000&dubbo=2.5.3&heartbeat=60000&interface=open.shopping.service.TestUserService&methods=saveUser&pid=
24560&revision=0.0.1-SNAPSHOT&side=consumer&timestamp=1507011254369): client( url:dubbo://127.0.0.1:20880/open.shopping.service.TestUserService?application=shopping-web-console&codec=dubbo&default.timeout=600000&dubbo=2.5.3&heartbeat=60000&interface=open.shopping.service.TestUserService&methods=saveUser&pid=24560&revision=0.0.1-SNAPSHOT&side=consumer&timestamp=1507011254369) failed to connect to server /127.0.0.1:20880, error message is:Connection refused: no further information

这是因为服务消费方没有找到自己所需要的服务。因此要首先启动服务提供方然后在启动服务消费方。

解决方法:

    <!--全局设置超时时间   10分钟,默认是1秒-->
    <dubbo:consumer timeout="600000" check="false"/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值