dubbo源码解析spring集成DubboNamespaceHandler配置参数②

说在前面
前期回顾

sharding-jdbc源码解析 更新完毕

spring源码解析 更新完毕

spring-mvc源码解析 更新完毕

spring-boot源码解析 更新完毕

rocketmq源码解析 更新完毕

dubbo源码解析 更新中

rocketmq源码解析系统架构篇 计划中

dubbo源码解析系统架构篇 计划中

sharding-sphere源码解析 计划中

github https://github.com/tianheframe

rocketmq 更新完毕

dubbo 更新中

spring-cloud-tianhe 从0到1实现一套微服务组件 更新中

mq-tianhe 从0到1实现一个mq框架

rpc-tianhe 从0到1实现一个rpc框架
更多源码解析欢迎关注天河聊架构微信公众号。

源码解析
接上次接续介绍spring集成配置参数解析。

protocolConfig <dubbo:protocol标签

public class ProtocolConfig extends AbstractConfig {

    private static final long serialVersionUID = 6913423882496634749L;

    // protocol name 通讯协议,默认dubbo,可选 hession、http、rmi、thrift、webservice等
    private String name;

    // service IP address (when there are multiple network cards available) ip地址,多个虚拟网卡时
    private String host;

    // service port
    private Integer port;

    // context path
    private String contextpath;

    // thread pool
    //    线程池类型
//    fixed java自带线程池
//    cached java自带线程池
//    limited 线程数只增大不会减少
//    eager java的线程池增加线程策略是核心线程数占满了往队列中放,队列也放满了没超过线程池的最大线程数才会创建线程,这个线程池增加线程的策略是currentPoolSize<submittedTaskCount<maxPoolSize
// 满足这个条件时会增加线程,submittedTaskCount是dubbo扩展的一个计数器,在执行线程的时候增加计数,线程执行完减少计数。
    private String threadpool;

    // thread pool size (fixed size) 线程池的最大线程数
    private Integer threads;

    // IO thread pool size (fixed size) io线程池线程数,主要指netty的work线程池线程数,默认Math.min(Runtime.getRuntime().availableProcessors() + 1, 32)
    private Integer iothreads;

    // thread pool's queue length 队列长度,默认0
    private Integer queues;

    // max acceptable connections 服务提供者最大可接收的线程数,0标识不限制,可以用次参数来做服务降级
    private Integer accepts;

    // protocol codec 编码格式,默认dubbo
    private String codec;

    // serialization 序列化方式,默认是hession2,可选fastjson、jdk、kryo
    private String serialization;

    // charset 编码格式,默认utf-8
    private String charset;

    // payload max length 请求和响应的最大字节 默认8m
    private Integer payload;

    // buffer size nio通讯缓冲区大小8192
    private Integer buffer;

    // heartbeat interval 心跳监测频次 60s
    private Integer heartbeat;

    // access log 处理日志路径
    private String accesslog;

    // transfort 网络传输方式,可选netty、mina、grizzly、http等
    private String transporter;

    // how information is exchanged
//    信息交换方式 header,默认HeaderExchanger
    // <dubbo:protocol exchanger=""/>
//    <dubbo:provider exchanger=""/>
    private String exchanger;

    // thread dispatch mode
    private String dispatcher;

    // networker
    private String networker;

    // sever impl
    private String server;

    // client impl
    private String client;

    // supported telnet commands, separated with comma.
    private String telnet;

    // command line prompt
    private String prompt;

    // status check
    private String status;

    // whether to register
    private Boolean register;

    // parameters
    // 是否长连接
    // TODO add this to provider config
    private Boolean keepAlive;

    // TODO add this to provider config
    private String optimizer;

    private String extension;

    // parameters
    private Map<String, String> parameters;

name 协议名,默认值dubbo、hession、http、rmi、thrift、webservice

host,ip地址,多个虚拟网卡时指定 本机ip

port 端口号,dubbo协议默认端口20881,rmi协议默认1099,http和hession协议默认80,如果指定-1会自动赋值为一个未使用的端口

threadpool,线程池类型,默认值fixed,cached 缓存线程池,limited 线程数只会增大不会减少,eager java的线程池增加线程策略是核心线程数占满了往队列中放,队列也放满了没超过线程池的最大线程数才会创建线程,这个线程池增加线程的策略是currentPoolSize<submittedTaskCount<maxPoolSize,满足这个条件时会增加线程

iothreads,io线程池线程数,主要指netty的work线程池线程数 Math.min(Runtime.getRuntime().availableProcessors() + 1, 32)

queues,队列长度 默认值0

accepts,服务提供者最大可接收的线程数 默认值0,标识不限制,可以用次参数来做服务降级
codec,编解码协议,默认值dubbo,http、hession、injvm、rmi、thrift、webservice
serialization,序列化方式,dubbo协议的默认序列化是hessian2, rmi协议是java, http协议是json、fastjson、kryo

payload,请求和响应的最大字节,默认8m
buffer,nio通讯缓冲区大小,8192
heartbeat,心跳监测频次

exchanger
<dubbo:protocol exchanger=""/>
<dubbo:provider exchanger=""/>

信息交换方式 header,默认HeaderExchanger
dispatcher 线程转发模式,上一篇文章有详细介绍
dubbo协议默认all

server,server实现,dubbo协议默认netty、http协议默认servlet
client,client实现,dubbo协议默认netty
register,是否注册,默认值true
keepAlive,是否长连接,默认值true

AbstractInterfaceConfig 服务配置, <dubbo:provider、<dubbo:service

public abstract class AbstractServiceConfig extends AbstractInterfaceConfig {

    private static final long serialVersionUID = 1L;

    // version
    protected String version;

    // group
    protected String group;

    // whether the service is deprecated 是否弃用 false
    protected Boolean deprecated;

    // delay service exporting 延迟加载服务的时间ms 0
    protected Integer delay;

    // whether to export the service 是否加载服务
    protected Boolean export;

    // weight 权重
    protected Integer weight;

    // document center
    protected String document;

    // whether to register as a dynamic service or not on register center 服务是否可以动态注册到注册中心
    protected Boolean dynamic;

    // whether to use token 是否使用token验证
    protected String token;

    // access log 处理日志文件
    protected String accesslog;
//    协议配置
    protected List<ProtocolConfig> protocols;

//    允许provider最大的并发数
    // max allowed execute times
    private Integer executes;

//    是否注册
    // whether to register
    private Boolean register;

    // warm up period
    private Integer warmup;

    // serialization 序列化方式
    private String serialization;

version,版本号,可根据此字段做服务隔离
group,服务组,此字段可做服务隔离
deprecated 是否弃用,默认值false
delay 服务导出延迟的时间,默认值0,导出
export 是否导出服务,默认值true
weight 权重
dynamic 服务是否可以动态注册到注册中心 默认值true
token 是否启用token验证 默认值false
accesslog 是否开启处理日志 ,默认值false
executes 允许provider最大的并发数,此字段可以用做限流 默认值0,不做限制
register 是否注册到注册中心 默认注册到所有的注册中心
warmup 服务预热 10 * 60 * 1000
serialization 序列化方式 dubbo协议默认hession2 fastjson、kryo

AbstractInterfaceConfig 接口配置,<dubbo:provider、<dubbo:service、<dubbo:consumer、<dubbo:reference标签

public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {

    private static final long serialVersionUID = -1559314110797223229L;

    // local impl class name for the service interface 接口的本地实现类名
    protected String local;

    // local stub class name for the service interface
    protected String stub;

    // service monitor
    protected MonitorConfig monitor;

    // proxy type 代理类型
    protected String proxy;

    // cluster type 容错类型
    protected String cluster;

    // filter
    protected String filter;

    // listener
    protected String listener;

    // owner
    protected String owner;

    // connection limits, 0 means shared connection, otherwise it defines the connections delegated to the
    // current service 连接方式,0表示共享连接,服务最大的连接数
//    consumer连接数
    protected Integer connections;

    // layer
    protected String layer;

    // application info
    protected ApplicationConfig application;

    // module info
    protected ModuleConfig module;

    // registry centers
    protected List<RegistryConfig> registries;

    // connection events 连接事件
    protected String onconnect;

    // disconnection events 断开连接事件
    protected String ondisconnect;

    // callback limits 回调次数
    private Integer callbacks;

    // the scope for referring/exporting a service, if it's local, it means searching in current JVM only.引用/导出服务的范围(如果是本地的)意味着只在当前JVM中搜索。
    private String scope;

local 服务代理的本地实现类名或者是否使用本地实现 默认值false
stub 是否使用默认的代理类名 默认值false
proxy 代理类型 默认值javassist

cluster 容错类型 默认值failover
available 使用可用的
failback 失败自动恢复,后台记录失败请求,定时重发
failfast 只发起一次调用,失败立即报警,一般用于非幂等操作
failover 失败自动切换,重试其他服务器,一般用于读操作,重试会带来更大的延迟
failsafe 失败安全,出现异常直接忽略,一般用于记录日志
forking 并行调用对个服务器,只要一个成功就返回,一般用于实时性比较高的读操作,需要浪费更多服务资源
filter filter 默认值default
listener listener 默认值default

connections consumer连接数,0标识共享连接,每个提供者的最大连接。对于短连接(如rmi、http和hessian),它是连接限制,但是对于长连接(如dubbo),它是连接计数。 默认值100

onconnect 连接事件方法名
ondisconnect 断开连接方法名
callbacks 异步回调次数限制 默认值1
scope 引用/导出服务的范围 local代表只从jvm内导出或引用服务

AbstractMethodConfig 方法配置


public abstract class AbstractMethodConfig extends AbstractConfig {

    private static final long serialVersionUID = 1L;

    // timeout for remote invocation in milliseconds 执行超时时间爱你
    protected Integer timeout;

    // retry times 重试次数
    protected Integer retries;

    // max concurrent invocations consumer最大并发数
    protected Integer actives;

    // load balance 负载均衡策略
    protected String loadbalance;

    // whether to async 是否异步
    protected Boolean async;

    // whether to ack async-sent 异步是否需要ack
    protected Boolean sent;

    // the name of mock class which gets called when a service fails to execute 服务调用失败后调用mock类
    protected String mock;

    // merger 结果集合并方法
    protected String merger;

    // cache 缓存
    protected String cache;

    // validation
    protected String validation;

timeout 超时时间 默认值1000ms
retries 重试次数 默认值2
actives consumer 最大并发数 0代表不限制

loadbalance 负载均衡策略 默认值random
random 随机
roundrobin 轮询
leastactive 最少活跃数
consistenthash 哈希一致性

async 是否异步 默认值false
sent 异步是否需要ack 默认值true

mock 默认值false
true表示使用默认的mock类名,即带有mock后缀的接口名。当RPC失败时调用它,例如超时或IO异常。mock类必须携带一个无参数构造函数。mock和本地代理的区别在于,总是在RPC之前调用本地代理,而只有在RPC之后出现异常时才调用mock。

merger 结果集合并方法
cache 缓存 lru、threadlocal、jcache
validation 是否启用JSR303标准注释验证

说在最后

本次解析仅代表个人观点,仅供参考。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值