Why use Dubbo?

osc_ 161difcz 2021-01-21 07:39:50
use dubbo

With the further development of service , More and more services , There are more and more calls and dependencies between services  
complex , The birth of service-oriented architecture (SOA),
Therefore, a series of corresponding technologies have been derived , Such as the provision of services 、 The service call 、 Connection processing 、 signal communication  
agreement 、 Serialization mode 、 Service discovery 、 Service routing 、 Log output and other behaviors are encapsulated in the service framework .
In this way, the service governance framework for distributed systems appears ,Dubbo  That's how it happened .
SOA And service governance
SOA( Service Oriented Architecture ) The concept has a long history , stay 10 Many years ago, it began to enter the eyes of our software developers .SOA It's a coarse grain 、 Loosely coupled Service Architecture , Between services through simple 、 Precisely define the interface for communication , It doesn't involve the underlying programming interface and communication model .SOA It can be seen as B/S Model 、Web Service The natural extension of technology .
Service governance , Also known as SOA government , It's used to manage SOA The process of adoption and implementation . The following is in 2006 in IBM Summary of the key points of service governance :
Service definition ( Scope of services 、 Interfaces and boundaries )
Service deployment lifecycle ( Life cycle stages )
Service versioning ( Including compatibility )
Service migration ( Commissioning and decommissioning )
Service registry ( Dependency relationship )
Service message model ( Canonical data model )
Service monitoring ( Carry out problem determination )
Service ownership ( Business organization )
Service Testing ( Repeat the test )
Service security ( Including acceptable scope of protection )
Limited to the level of technological development at that time , The majority of software designers and developers are interested in SOA And the technology cognition of service governance mainly stays in Web Service and ESB Bus and other technologies and specifications , It's not really fully implemented in software development .
Dubbo Open source
until 2011 year 10 month 27 Japan , Alibaba has opened its own SOA The core framework of service-oriented governance Dubbo, Service governance and SOA The design concept of the software industry in China began to gradually land , And it's widely used .
Dubbo As Alibaba's internal SOA The core framework of service-oriented governance , stay 2012 It's been every day for 2000+ Service offerings 3,000,000,000+ Secondary traffic support , And is widely used in Alibaba Group's member sites .Dubbo since 2011 After years of open source , It has been used by many non Alibaba companies , There are dangdang.com 、 Netease koala and other Internet companies , There is also China Life Insurance 、 Qingdao, Haier and other traditional enterprises .
Dubbo brief introduction
Dubbo It's a high performance service framework , Committed to providing high performance and transparency RPC Remote service invocation scenarios , as well as SOA Service governance solution , Make applications available through high performance RPC Realize the output and input functions of services , and Spring Frameworks can be seamlessly integrated .
As a distributed service framework , as well as SOA Treatment plan ,Dubbo Its core functions mainly include :
#remoting: The foundation of telecommunication , Provide for a variety of NIO Framework Abstract encapsulation , Include “ Synchronous to asynchronous ” and “ request - Respond to ” Mode of information exchange .
#Cluster: The core of the service framework , Provide remote over call based on interface method , Including multi protocol support , It also provides cluster support for soft load balancing and fault tolerance mechanism .
#registry: Service registry , Enable service consumers to dynamically search for service providers , Make the address transparent , Enable service providers to smoothly add or reduce machines
The following figure comes from Dubbo Official website , Describes the service registry 、 service provider 、 Service consumer 、 Call relationship between service monitoring centers , The details are shown in the following figure :

 Why use Dubbo?
Here we just add some details from the point of view of the specific implementation of the source code , Include Invoker、Extensier Other aspects . Any details that have been officially introduced , We don't add to the cake , The official documents are detailed enough , The positioning of this document is to supplement the implementation details , It's based on the fact that I'm going to Dubbo add to web service In the course of the agreement , Some of the difficulties we encountered .
The service provider exposes the detailed process of a service
 Why use Dubbo?

The figure above shows the main process of exposing services by service providers :
First ServiceConfig Class to get the actual class of external service ref( Such as :HelloWorldImpl), And then through ProxyFactory Class getInvoker Methods use ref Generate a AbstractProxyInvoker example , At this stage, we will complete the specific services to Invoker The transformation of . The next step is Invoker The switch to Exporter The process of .
Dubbo The key to dealing with service exposure is Invoker The switch to Exporter The process of ( As shown in the red part of the picture above ), Now let's Dubbo and RMI The implementation of these two typical protocols is described :
Dubbo The implementation of the
Dubbo Agreed Invoker To Exporter It happened in DubboProtocol Class export Method , It's mainly about opening socket Listening Services , And receive all kinds of requests from the client , Communication details by Dubbo Realize it by yourself .
RMI The implementation of the
RMI Agreed Invoker To Exporter It happened in RmiProtocol Class export Method , It passes through Spring or Dubbo or JDK To achieve RMI service , The communication details are made up of JDK The bottom layer , This saves a lot of work .
Service consumers consume a detailed process of service

 Why use Dubbo?

The picture above shows the main process of service consumption :
First ReferenceConfig Class init Method call Protocol Of refer Method generation Invoker example ( As shown in the red part of the picture above ), This is the key to service consumption . Next, put Invoker Convert to the interface required by the client ( Such as :HelloWorld).
About every agreement such as RMI/Dubbo/Web service Wait for them to call refer Method generation Invoker The details of the example are similar to those described in the previous chapter .
It's all over my eyes Invoker
because Invoker yes Dubbo A very important concept in the domain model , Many design ideas are close to it . This makes Invoker*** In the whole implementation code , For the first contact Dubbo People who , It's really confusing .
Let's use a simplified diagram to illustrate the two most important Invoker: Services provide Invoker And service consumption Invoker:

 Why use Dubbo?

To better explain this picture above , Let's illustrate it with code examples of service consumption and provider :
Service consumer code
# Service consumer code public class DemoClientAction { private DemoService demoService; public void setDemoService(DemoService demoService) { this.demoService = demoService; } public void start() { String hello = demoService.sayHello("world" + i); } }
In the above code ’DemoService’ It's the consumer side of the service in the picture above proxy, User code through this proxy Call its corresponding Invoker(DubboInvoker、 HessianRpcInvoker、 InjvmInvoker、 RmiInvoker、 WebServiceInvoker Any one of them ), And the Invoker Realize the real remote service call .
# Service provider code public class DemoServiceImpl implements DemoService { public String sayHello(String name) throws RemoteException { return "Hello " + name; } }
The above class will be encapsulated as a AbstractProxyInvoker example , And create a new Exporter example . So when the network communication layer receives a request , We'll find the corresponding one Exporter example , And call its corresponding AbstractProxyInvoker example , So the service provider's code is actually called .
Dubbo There are some others in the book Invoker class , But the two above are the most important .
Extensier A complete analysis of
Extensier yes Dubbo A very important class in , Rigid contact Dubbo Source code people will be a little confused when they look at this class , This class is very important , It's like in the kitchen “ Chef ”, According to the needs of users at any time to put all kinds of “ The ingredients ” Cook it .
Let's talk about it in detail with specific code Extensier The implementation of the , Here is ServiceConfig A line of code in a class :
private static final Protocol protocol = Extensier.getExtensier(Protocol.class).getAdaptiveExtension();
The program flow chart of the above code is as follows ( Let's say it's the first time this line of code is executed ):
 Why use Dubbo?

The two most important ways in the process are getExtensionClasses and createAdaptiveExtensionClass( The red part of the picture ), The two methods are analyzed in detail :
This method mainly reads META-INF/services/ Contents of corresponding files in the directory , In this example code , Is read META-INF/services/com.alibaba.dubbo.rpc.Protocol Contents of the file , The details are as follows :
com.alibaba.dubbo.registry.support.RegistryProtocol com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol com.alibaba.dubbo.rpc.protocol.injvm.InjvmProtocol com.alibaba.dubbo.rpc.protocol.rmi.RmiProtocol com.alibaba.dubbo.rpc.protocol.hessian.HessianProtocol com.alibaba.dubbo.rpc.protocol.webservice.WebServiceProtocolbr/> It analyzes every line in the file ( Each row corresponds to a class ), Analyze these classes , If you find any class Annotation yes @Adaptive, Then find the corresponding AdaptiveClass 了 , But because of Protocol There is no class in the file Annotation yes @Adaptive, So in this example, the method doesn't find a corresponding AdaptiveClass.
This method is based on getExtensionClasses No way to find AdaptiveClass Is called , This method mainly generates a new class in memory by bytecode , It has AdaptiveClass The function of ,Protocol It's in this way that AdaptiveClass Class .

本文为[osc_ 161difcz]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云