6、Dubbo-配置(1)

覆盖关系
下图展示了配置覆盖关系的优先级,从上到下优先级依次降低:


启动时检查

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.3.xsd"> <context:component-scan base-package="com.cr.service.impl"></context:component-scan>
<!-- 、指定当前服务/应用的名字(同样的服务名字,不要和别的服务同名 -->
<dubbo:application name="user-order-consumer"></dubbo:application> <!-- 、指定注册中心的位置 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181" /> <!-- 、声明 需要调用的远程服务接口:生成远程服务代理-->
<!-- userService注册到容器中 -->
<dubbo:reference interface="com.cr.service.UserService" id="userService" check="false"/> <!-- 监控中心 -->
<dubbo:monitor protocol="registry"></dubbo:monitor> </beans>

<!-- 配置当前消费者的同意规则:所有的服务都不检查 -->
<dubbo:consumer check="false"></dubbo:consumer>

注意:不仅可以配置服务启动时检查还可以配置注册中心启动时检查

超时设置
1、对于服务提供方的代码进行睡眠4秒中
public class UserServiceImpl implements UserService {
@Override
public List<UserAddress> getUserAddressList(String userId) {
UserAddress address1 = new UserAddress(, "安徽合肥蜀山区", "", "程老师", "否", "");
UserAddress address2 = new UserAddress(, "安徽合肥包河区", "", "程老师", "否", "");
List<UserAddress> list = new ArrayList<UserAddress>();
list.add(address2);
list.add(address1);
try {
Thread.sleep();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
}
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
com.alibaba.dubbo.common.bytecode.proxy0@704deff2
用户id:
Exception in thread "main" com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method
getUserAddressList in the service com.cr.service.UserService. Tried 3 times of the providers
[169.254.77.19:20080] (1/1) from the registry 127.0.0.1:2181 on the consumer 169.254.77.19 using the dubbo version 2.6.2. Last error is: Invoke remote method timeout. method:
getUserAddressList, provider: d
ubbo://169.254.77.19:20080/com.cr.service.UserService?anyhost=true&application=user-order-consumer&check=false&default.check=false&dubbo=2.6.2&generic=false&interface=com.cr.service.UserService&methods=getUserAddressList&monitor=dubbo%3A%2F%2F127.0.0.1%3A2181%2Fcom.alibaba.dubbo.regi
此时的超时没有进行配置,可知其有默认值


可知默认值是一秒

可以理解在线程阻塞的时间内,超时等待5秒
<dubbo:reference interface="com.cr.service.UserService" id="userService" timeout=""/>
此时的等待时间大于线程休眠时间(5s > 4s)

<dubbo:consumer check="false" timeout=""></dubbo:consumer>
此时需要考虑两个配置同时配置的优先级
http://dubbo.apache.org/zh-cn/docs/user/configuration/xml.html

(建议由服务提供方设置超时,因为一个方法需要执行多长时间,服务提供方更清楚,
如果一个消费方同时引用多个服务,就不需要关心每个服务的超时设置)

精确到方法!!!
<dubbo:reference interface="com.cr.service.UserService" id="userService" timeout="5000">
<dubbo:method name="getUserAddressList" timeout="2000"></dubbo:method>
</dubbo:reference>
此时时方法的配置生效 时间为2000ms
统一提供

6、Dubbo-配置(1)的更多相关文章
- Dubbo配置方式详解
Dubbo 是一个分布式服务框架,致力于提供高性能和透明化的 RPC 远程服务调用方案,是阿里巴巴 SOA 服务化治理方案的核心框架,每天为 2,000+ 个服务提供 3,000,000,000+ 次 ...
- DUBBO配置规则详解
研究DUBBO也已经大半年了,对它的大部分源码进行了分析,以及对它的内部机制有了比较深入的了解,以及各个模块的实现.DUBBO包含很多内容,如果想了解DUBBO第一步就是启动它,从而可以很好的使用它, ...
- [转载,感觉写的非常详细]DUBBO配置方式详解
[转载,感觉写的非常详细]DUBBO配置方式详解 原文链接:http://www.cnblogs.com/chanshuyi/p/5144288.html DUBBO 是一个分布式服务框架,致力于提供 ...
- dubbo配置清单-超详细版
服务发布者 在服务发布者的springboot主配置文件application.properties中添加dubbo配置 #dubbo服务名 spring.dubbo.application.name ...
- dubbo配置约束
此处主要记录dubbo配置的一些约束规则. 采用官网提供的原文,描述如下: 一.XML配置(官网原文) 以 timeout 为例: 方法级优先,接口级次之,全局配置再次之. 如果级别一样,则消费方优先 ...
- dubbo配置指南
dubbo配置指南 SLA配置在此完成!Service Layer Agreement ApplicationConfig 应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者. Regist ...
- Dubbo配置注册中心设置application的name使用驼峰命名法存在的隐藏项目启动异常问题
原创/朱季谦 首先,先提一个建议,在SpringBoot+Dubbo项目中,Dubbo配置注册中心设置的application命名name的值,最好使用xxx-xxx-xxx这样格式的,避免随便使用驼 ...
- 10 Dubbo 配置实战
Dubbo 配置实战 快速入门 dubbo 建议看这篇文章是在学习了快速入门 dubbo 那篇文章的基础上来学习 配置说明 文档地址 https://dubbo.apache.org/zh/index ...
- dubbo 配置解析
1.dubbo 常用配置 <dubbo:service/> 服务配置,用于暴露一个服务,定义服务的元信息,一个服务可以用多个协议暴露,一个服务也可以注册到多个注册中心.eg.<dub ...
- dubbo配置
Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单的模 ...
随机推荐
- spring data jpa(一)
第1章 Spring Data JPA的快速入门 1.1 需求说明 Spring Data JPA完成客户的基本CRUD操作 1.2 搭建Spring Data JPA的开发环境 1. ...
- sc create SVN-Service binpath= "D:\Program Files\Svn\bin\s vnserve.exe --service -r E:\repository\svn" displayname= "SVN-Service" start= au to depend= Tcpip [SC] OpenSCManager 失败 5:
在安装SVN服务时就会出现如下问题: C:\Users\gushangzao>sc create SVN-Service binpath= "D:\Program Files\Svn\ ...
- eclipse中实现文本换行
Eclipse 使用系统内置的“ Text Editor ”做为文本编辑器,这个文本编辑器有一个问题,就是文本无法换行. 扩展插件 WordWrap 可以实现文本换行 安装方法: ...
- Hibernate入门(四)—— 查询
一.Hibernate查询 1.Hibernate检索(查询)方式的分类 OID检索 :根据主键查询,get/load 对象导航检索 :通过一个对象获得其关联对象.[重点] Category cate ...
- asp.net WebService的一个简单示例
不同的系统之间经常会需要数据的交换对接,而Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范 ...
- C#语言总结1
C#C#定义: C#是一门面向对象.面向组件的一门语言,是.NET的一部分. 程序结构: 命名空间 类{ 属性 方法 main函数入口 } 数据类型: C#的数据类型分为:值类型(Value type ...
- C++11 之for 新解 auto
C++11 之for 新解 auto 前言 C++11这次的更新带来了令很多C++程序员期待已久的for range循环,每次看到javascript, lua里的for range,心想要是 ...
- Visual Studio解决方案vs2005/vs2008/vs2010/vs2012/vs2013/vs2015版本互相转换工具
原文:http://blog.csdn.net/xiejiashu/article/details/52397641 本文转自EasyDarwin团队成员Alex的博客:http://blog.c ...
- Oracle 给字符串补空格、补0
利用lpad().RPAD()函数来实现给字符串补空格或补0的功能: 一.lpad()lpad函数将左边的字符串填充一些特定的字符其语法格式如下:lpad(string,n,[pad_string]) ...
- 同步(Synchronous)和异步(Asynchronous)的概念
web项目中的同步与异步 在我们平时的web项目开发中会经常听到ajax请求这样一个称呼,在web项目中可以通过js或者jquery发送同步请求又或者异步请求,同步请求呢往往代表着你必须等待这次请求结 ...