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采用的是一种非常简单的模 ...
随机推荐
- Android中自定义弹出PopupWindow后返回按键失效的问题解决
PopupWindow出现之后,默认的是所有的操作都无效的,除了HOME键.而且是可以操作后面的界面的.想要锁定后面的界面,很简单,只需要让PopupWindow是focusable的:popupWi ...
- 述一个程序员的技能:系统安装(win7版)idea配置
idea配置:http://www.phperz.com/article/15/0923/159043.html 作为一名计算机专业出身的程序员,组装电脑和安装系统是基本技能.打造一个安全稳定高效的开 ...
- layui——上传图片,并实现放大预览
一般上传文件后会返回文件的路径,然后存储到数据库,那么首先实现上传后的放大和删除功能 function uploadSmallPic() { var upload = layui.upload; up ...
- 项目中遇到的问题——jsp:include
昨晚记错了,项目中用的是这个<jsp:attribute>,不过没关系,都差不多!原理是传参数 具体用法: 假设有两个tag文件 aaa 和 bbb aaa有两个属性:name age ...
- Redis-概述
Redis支持的类型: String,List,Map,Set,Sorted set Redis的持久化: 1.Redis DataBase (RDB): RDB是在某个时间点将数据写入一个临时文件, ...
- CSS,js,html
图片盗链问题使用以下meta标签解决 <meta name="referrer" content="never"> Chrome 中文界面下默认会将 ...
- HTML5触摸事件演化tap事件
触摸事件是移动浏览器特有的HTML5事件,虽然click事件在pc和移动端更通用,但是在移动端会出现300ms延迟,较为影响用户体验,300ms延迟来自判断双击和长按,因为只有默认等待时间结束以确定没 ...
- Luogu3307:[SDOI2013]项链
传送门 求每个珠子的方案数 即有序的求三元组 \((x,y,z),x,y,z\le a\) 满足 \(gcd(x,y,z)=1\) 设 \(G_i\) 表示 \(i\) 个小于等于 \(a\) 的有序 ...
- 51Nod 算法马拉松23 开黑记
惨啊……虽然开了半天黑,但是还是被dalao们踩了…… 第二次开黑,还是被卡在rank20了,我好菜啊……= = 写一写比赛经过吧…… 看到题之后习惯性都打开,A~D看上去似乎并没有什么思路,F应该是 ...
- Sql Server 2012 Local DB发布到服务器端后无法访问
背景 基于Windows认证的Web application, 通过Visual Studio 2013创建的LocalDB位于App_Data目录下 现象 本地调试没有任何问题.发布到服务器(Win ...