Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to quickly grasp the principle and source code of Dubbo in a short time

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to quickly grasp the principle and source code of Dubbo in a short period of time. Many people may not understand it very well. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

The premise of reading the source code

Before reading a technical framework, or the source code of an open source project, you must understand what the framework is for, to put it bluntly, that is, at least you know how to use the framework, in what scenarios, what holes you will encounter in the process of using it, and how to solve it. The easiest and most effective way to learn a framework is its official documentation. Dubbo is no exception. When I was learning Dubbo, I first read the official documents of Dubbo. I basically didn't read any other articles or materials. Why? Because the official documents of Dubbo are the most authoritative and reliable.

Even if you have not used the Dubbo framework in your project, you can write a simple example program based on Dubbo according to the official documentation of Dubbo, through which you can quickly understand Dubbo.

Why read the source code?

Before reading the source code, you need to know clearly why you want to read the source code, with questions to look at the source code. If you want to see the source code of the framework, there are only two situations: one is that you encounter a problem that cannot be solved through documentation or other technical materials in the project, and you want to find a solution through the source code; the other is curious about the underlying implementation of the framework. How is such a powerful technology implemented? And I, basically belong to the latter. In the highly concurrent e-commerce systems that I have experienced with hundreds of millions of users, some of the core subsystems use Dubbo. After performance tuning, Dubbo performs well. I was curious: how does Dubbo withstand such high concurrency? How is it implemented internally?

Secondly, before reading the source code, you should ask yourself a few questions. For example, I made a lot of questions clear before I looked at the Dubbo source code, such as: how does Dubbo implement the RPC service? How do service providers and callers interact? How does Dubbo encapsulate a network call to look the same as calling a local method? How does Dubbo implement service governance? And so on a series of questions, I remember that I asked myself hundreds of questions before looking at the source code. Looking at the source code with questions allows you to get twice the result with half the effort, not only for Dubbo, but also for other frameworks.

Also, do not look at the source code in order to see the source code, many friends read a lot of the source code of the framework, but soon forgot it, just like not looking at it, and wasted a lot of time. This is a typical look at the source code in order to look at the source code, and did not delve into the implementation principles and details of the framework. If you encounter something that you do not understand, you can skip it first, record it, and so on, after reading the related code, and then turn around to re-comb the source code that you do not understand.

What technologies are used by the framework

Before reading the source code, it is also important to understand what technologies are used in the framework. Have a general understanding of the technology used. For example, SPI, time round timing tasks, service registration and discovery, Netty, serialization, custom protocols and other technologies are used in Dubbo. Therefore, before reading the source code, you should have a general understanding of these technologies.

For example, before looking at the Dubbo source code, I already learned about the Netty used in the underlying network interaction of Dubbo. Shortly after my work, I deeply studied the source code of Netty, which helped me to better understand the network programming part of Dubbo when I read the Dubbo source code.

So, one minute on the stage, ten years of work off the stage, before reading the Dubbo source code, I also made full preparations.

What to pay attention to when reading the source code

Any technical framework, or open source project, must be created to solve certain scenarios, such as Dubbo, as we all know, Dubbo as a distributed service governance framework, a typical use scenario is distributed systems.

Secondly, behind an excellent technical framework or open source project must contain the principles and implementation of many other technologies. We also take Dubbo as an example. In Dubbo, in order to call a remote RPC service just like calling a local service in a distributed scenario, it needs to implement at least the following functions:

Performance communication between services. Service invocation needs to be load-balanced, highly available and flow-limited. Service governance. Highly reliable and fault tolerant. Services can be automatically registered and discovered.

What excellent open source frameworks does Dubbo use to implement these functions? How are these open source frameworks Dubbo integrated? Is it hard-coded integration? Or is there a better way? All these require us to find the answer in the source code when we read the source code.

The way to read the source code

I summed up the way to read the source code as follows: first overall and then partial, first macro and then micro, first rough and then details.

What do you mean? It is time to look at the source code, first grasp the design principle and design concept of the source code as a whole, and understand how the source code is realized as a whole. For example, in Dubbo, network programming is based on Netty, so you can learn about it first and know about it. Grasp the basic framework source code as a whole, and then bump into the specific implementation from the details, for example, how to use Netty to achieve network interaction in Dubbo?

Remember, when reading the source code, don't start to cling to the details of the source code before you understand the overall design principle and the overall source code design. Otherwise, you will lose yourself in the source code.

How to verify that you have mastered the source code?

It is not enough to read the source code, but also to practice it yourself. as the saying goes, "practice is the only standard for mastery and arrangement." If you don't practice, how can you know if you have mastered it or not?

I divided the practice part into two parts: hands-on practice while looking at the source code, and hands-on practice after looking at the source code.

In the process of looking at the source code, hands-on practice means: in the process of looking at the source code, record what you do not understand, consult the official website documents or other materials, if it is due to your own lack of technical ability, do not understand, it is necessary to recharge yourself in time to supplement the relevant knowledge. If you encounter an implementation that you think is better, you can mark your understanding by commenting on the code of the framework. For example, when I read the Dubbo source code, I marked a lot of comments.

After looking at the source code, be sure to do it. After reading the overall source code of Dubbo, if you think you have mastered Dubbo, you might as well implement a RPC framework on your own, and see what are the differences between your framework and the Dubbo framework, and why the Dubbo framework is implemented in this way. If you look at the source code of Dubbo with the problem, you will certainly understand it more deeply. And I, after looking at the source code of the Dubbo framework, did the same.

After reading the above, do you have any further understanding of how to quickly grasp the principle and source code of Dubbo in a short time? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 240

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report