dubbo各个模块简介
所属分类 dubbo
浏览量 910
registry 注册中心 Multicast Zookeeper Redis Simple 等实现
cluster 集群模块
common Util 类和通用模型
config 配置模块
rpc 远程调用模块
remoting 远程通信模块
container 容器模块
filter 过滤器
monitor 监控模块
serialization 序列化模块
bootstrap
plugin 插件
demo 例子
cluster 集群模块
Merge the directory invokers to a virtual invoker.
将多个服务提供方伪装成一个提供方,实现 负载均衡, 容错,路由等功能
集群地址列表 静态配置 或 基于注册中心
Invoker
cluster
集群容错模式
failover failfast failsafe failback forking
FailsafeClusterInvoker
失败安全,出现异常时,直接忽略,通常用于写入审计日志等操作
FailoverClusterInvoker
失败转移,当出现失败,重试其它服务器,通常用于读操作,但重试会带来更长延迟
int retryCount = getUrl().getMethodParameter(invocation.getMethodName(), Constants.RETRIES_KEY, Constants.DEFAULT_RETRIES) + 1;
FailbackClusterInvoker
失败自动恢复,后台记录失败请求,定时重发,通常用于消息通知操作
list Directory (static registry)
route Router (script condition)
select LoadBalance (Random RandomRobin LeastActive)
invoke Invoker
com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker
public Result invoke(final Invocation invocation) throws RpcException {
checkWheatherDestoried();
LoadBalance loadbalance;
List> invokers = list(invocation);
if (invokers != null && invokers.size() > 0) {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
.getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
} else {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
}
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
return doInvoke(invocation, invokers, loadbalance);
}
protected List> list(Invocation invocation) throws RpcException {
List> invokers = directory.list(invocation);
return invokers;
}
configurator 配置 采用URL作为配置信息的统一格式
common Util 类和通用模型
com.alibaba.dubbo.common.URL
rpc 远程调用模块
抽象各种协议,动态代理,只包含一对一的调用
com.alibaba.dubbo.rpc.protocol
DubboProtocol extends AbstractProtocol
public abstract class AbstractProtocol implements Protocol
HttpProtocol
HessianProtocol
HttpProtocol
InjvmProtocol
MemcachedProtocol
RedisProtocol
RmiProtocol
remoting 远程通信模块
提供多种客户端和服务端通信功能
支持 Netty Mina Grizzly 等 NIO 框架
Exchange Transport
exchange
抽象了 Request 和 Response,并为其添加很多特性
transport
抽象网络传输层,只负责抽象单向消息传输
请求消息由 Client 端发出,Server 端接收
响应消息由 Server 端发出,Client端接收
transport 是在网络库上层的一层抽象
com.alibaba.dubbo.remoting.transport.netty.NettyServer
com.alibaba.dubbo.remoting.transport.netty.NettyClient
com.alibaba.dubbo.remoting.transport.AbstractEndpoint
com.alibaba.dubbo.remoting.Endpoint
void send(Object message) throws RemotingException;
// sent 是否已发送完成
void send(Object message, boolean sent) throws RemotingException;
URL getUrl();
ChannelHandler getChannelHandler();
InetSocketAddress getLocalAddress();
void close();
void close(int timeout);
container 容器模块
Container接口 main方法加载
com.alibaba.dubbo.container.Container
@SPI("spring")
public interface Container
com.alibaba.dubbo.container.spring.SpringContainer
/META-INF/dubbo/internal/com.alibaba.dubbo.container.Container
spring=com.alibaba.dubbo.container.spring.SpringContainer
javaconfig=com.alibaba.dubbo.container.javaconfig.JavaConfigContainer
jetty=com.alibaba.dubbo.container.jetty.JettyContainer
log4j=com.alibaba.dubbo.container.log4j.Log4jContainer
logback=com.alibaba.dubbo.container.logback.LogbackContainer
filter
com.alibaba.dubbo.rpc.Filter
com.alibaba.dubbo.rpc.filter.TimeoutFilter
执行timeout,log记录 ,类似慢查询日志
@Activate(group = Constants.PROVIDER)
public class TimeoutFilter implements Filter {
private static final Logger logger = LoggerFactory.getLogger(TimeoutFilter.class);
public Result invoke(Invoker> invoker, Invocation invocation) throws RpcException {
long start = System.currentTimeMillis();
Result result = invoker.invoke(invocation);
long elapsed = System.currentTimeMillis() - start;
if (invoker.getUrl() != null && elapsed > invoker.getUrl().getMethodParameter(invocation.getMethodName(),"timeout", Integer.MAX_VALUE)) {
if (logger.isWarnEnabled()) {
logger.warn("invoke time out. method: " + invocation.getMethodName()
+ "arguments: " + Arrays.toString(invocation.getArguments()) + " , url is "
+ invoker.getUrl() + ", invoke elapsed " + elapsed + " ms.");
}
}
return result;
}
}
serialization 序列化模块
@SPI("hessian2")
public interface Serialization
com.alibaba.dubbo.common.serialize.support.hessian.Hessian2Serialization
com.alibaba.dubbo.common.serialize.support.json.FastJsonSerialization
上一篇
下一篇
dubbo注册过程简介
dubbo获取线程池等信息
dubbo SPI 机制简介
基于netty的RESTFUL框架
Java动态代理InvocationHandler例子
Linux常用命令汇总