分布式服务Dubbo从入门到"精通"之Schema实现

 

了解更多技术文章请点击原文链接

 

前言

 

尽管使用了Dubbo许久,但其实对于其了解还是九牛一毛,上个月通读了Netty实战(粗略的了解),突然有了解读Dubbo源码的欲望,时不待我,那就赶紧开始吧。

熟悉Dubbo的朋友,可能都知道其采用全spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spring的Schema扩展进行加载。

当然,如果你不想使用Spring配置,而希望通过API的方式进行调用,Dubbo也是支持的,但是官方是不推荐的(原因你猜)。

今天,就跟大家聊一聊Dubbo是如何基于Schema实现的。

准备

1121698433

具体实现,需要使用到一下几个配置或者是类:
spring.handlers:解析所使用的类
spring.schemas:自定义标签的路径
DubboNamespaceHandler.Java:处理器
DubboBeanDefinitionParser.java:解析器
xxxxConfig.java:JavaBean建模

实现

这里我们以dubbo:application做案例介绍

实体类ApplicationConfig.java

位于com.alibaba.dubbo.config包下,截取部分代码:

public class ApplicationConfig extends AbstractConfig { private static final long serialVersionUID = 5508512956753757169L; private String name; private String version; private String owner; private String organization; private String architecture; private String environment; private String compiler; private String logger; private List<RegistryConfig> registries; private MonitorConfig monitor; private Boolean isDefault; public ApplicationConfig() { } public ApplicationConfig(String name) { setName(name); } 

编写dubbo.xsd文件

位于META-INF下,截取部分代码:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> <xsd:schema xmlns="http://code.alibabatech.com/schema/dubbo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:tool="http://www.springframework.org/schema/tool" targetNamespace="http://code.alibabatech.com/schema/dubbo"> <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/> <xsd:import namespace="http://www.springframework.org/schema/beans"/> <xsd:import namespace="http://www.springframework.org/schema/tool"/> <xsd:annotation> <xsd:documentation><![CDATA[ Namespace support for the dubbo services provided by dubbo framework. ]]></xsd:documentation> </xsd:annotation> <xsd:complexType name="applicationType"> <xsd:attribute name="id" type="xsd:ID"> <xsd:annotation> <xsd:documentation><![CDATA[ The unique identifier for a bean. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="name" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation><![CDATA[ The application name. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="version" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ The application version. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="owner" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ The application owner name (email prefix). ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="organization" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ The organization name. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="architecture" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ The architecture. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="environment" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ The application environment, eg: dev/test/run ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="compiler" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ The java code compiler. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="logger" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ The application logger. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="registry" type="xsd:string" use="optional"> <xsd:annotation> <xsd:documentation><![CDATA[ The application registry. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="monitor" type="xsd:string" use="optional"> <xsd:annotation> <xsd:documentation><![CDATA[ The application monitor. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> <xsd:attribute name="default" type="xsd:string" use="optional"> <xsd:annotation> <xsd:documentation><![CDATA[ Is default. ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> 

转载于:https://www.cnblogs.com/Gamay/p/7150406.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值