Dubbo介绍

介绍:

Dubbo是阿里巴巴开源出来的一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及作为SOA服务治理的方案。它的核心功能包括:

  • l  remoting: 远程通讯基础,提供对多种NIO框架抽象封装,包括“同步转异步”和“请求-响应”模式的信息交换方式。
  • l  Cluster: 服务框架核心,提供基于接口方法的远程过程调用,包括多协议支持,并提供软负载均衡和容错机制的集群支持。
  • l  registry: 服务注册中心,使服务消费方能动态的查找服务提供方,使地址透明,使服务提供方可以平滑增加或减少机器。
    由于Dubbo团队的文档和代码都非常优秀,所以更多关于dubbo的方方面面请参考网站http://code.alibabatech.com/wiki/display/dubbo/Home-zh。

这里我们只是补充一下从源码具体实现角度来看的某些细节方面,包括Invoker、ExtensionLoader等方面。任何官方已经介绍过的细节,我们不做画蛇添足,官方文档已经足够详实了,这篇文档的定位是补充实现的相关细节

dubbo能做什么

  • 透明化的远程方法调用
  • – 就像调用本地方法一样调用远程方法
  • – 只需简单配置,没有任何API侵入。
  • • 软负载均衡及容错机制
  • – 可在内网替代F5等硬件负载均衡器
  • • 服务自动注册与发现
  • – 不再需要写死服务提供方地址,注册中心基于接口名查询服务提
  • 供者的IP地址,并且能够平滑添加或删除服务提供者
  • 服务的治理工具。

image.png

dubbo 架构:

image.png

Dubbo的使用方法

发布服务

<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
     xmlns:context="http://www.springframework.org/schema/context"
 xmlns:p="http://www.springframework.org/schema/p"
     xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
     http://www.springframework.org/schema/context 
 http://www.springframework.org/schema/context/spring-context-4.0.xsd
     http://code.alibabatech.com/schema/dubbo 
 http://code.alibabatech.com/schema/dubbo/dubbo.xsd
     http://www.springframework.org/schema/aop 
 http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
 http://www.springframework.org/schema/tx 
 http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
 http://www.springframework.org/schema/util 
 http://www.springframework.org/schema/util/spring-util-4.0.xsd">
 
     <!-- 配置包扫描器 -->
     <context:component-scanbase-package="com.liwei.service"></context:component-scan>
 
     <!-- 发布dubbo服务 -->
     <!-- 提供方应用信息,用于计算依赖关系 -->
     <dubbo:application name="demo-manager" />
     <!-- 使用multicast广播注册中心暴露服务地址 -->
     <!-- <dubbo:registry address="multicast://224.5.6.7:1234"/>    //广播式,不推荐使用-->
     <dubbo:registry protocol="zookeeper" address="192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183" />//推荐
     <!-- 用dubbo协议在20880端口暴露服务 -->
     <dubbo:protocol name="dubbo" port="20880" />
     <!-- 声明需要暴露的服务接口 -->
     <dubbo:service interface="com.liwei.service.ItemService"  ref="itemServiceImpl" />
</beans>
<!-- 和本地服务一样实现远程服务 -->
<bean id="xxxService" class="com.xxx.XxxServiceImpl" />
<!-- 增加暴露远程服务配置 -->
<dubbo:service interface="com.xxx.XxxService" ref="xxxService" />

调用服务

<!-- 增加引用远程服务配置 -->
<dubbo:reference id="xxxService" interface="com.xxx.XxxService" />
<!-- 和本地服务一样使用远程服务 -->
<bean id="xxxAction" class="com.xxx.XxxAction">
       <property name="xxxService" ref="xxxService" />
</bean>
posted @   汉源魂  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示