Having finished the Dubbo cluster fault tolerance series, we now move on to the more important parts of the dubbo interview: service publication and service reference.
-
Dubbo source code analysis – cluster fault tolerant architecture design
-
Dubbo source code parsing – directory
-
Dubbo source code parsing – router
-
Dubbo source code parsing – detailed explanation of cluster
-
Dubbo LoadBalance
What happens during service publication
What are the protocols for Dubbo? What are the characteristics between them? What are the default values
What is local exposure and remote exposure, and the difference
As we all know, Dubbo is an open source project of Alibaba. A few days ago, Alibaba not only released the code specification manual, but also released the corresponding plug-in. From this point, we know that Alibaba attaches great importance to this code specification. So what does that have to do with dubbo’s launch today? Of course, a standard project is bound to have a sound log system. Those of you who have done other development such as iOS development know that this console output is not something you can output in a production environment, and too many logs can sometimes be the same as no logs at all. So let’s take a look at what the log output is when the service is started.
Here I’ve highlighted the key areas in different colored boxes, six colors in total, and I’m going to walk you through some of the actions of the release process from top to bottom
Exposing local services
Exposing remote services
Start the netty
Connect the zookeeper
The zookeeper registered
Listening to the zookeeper
People often ask how to look at the source code. To understand this service release, documentation is a good place to start, as shown below
Of course these are for people who are already familiar with the source code, and my source code parsing class documents are for people who are not familiar with the source code.
In fact, my every Monday more dubbo source code series articles, my original intention has the following two, one is to do system sharing, such as dubbo series articles, I will never be less than the kernel, service release, service reference, codec these four modules to analyze, if there is time, I will copy a simple Dubbo framework. Another original intention is to share their thinking process with everyone, in the process of sharing, in fact, is to answer the question “how to read the source code”
Then get ready for Wuling Hongguang and set out for Qiu Mingshan
Set out on The Autumn famous Mountain
In my early days as an Android developer, I realized that everyone around me was dying at one point: the configuration environment. For look at the source, a lot of people most often ask a word is, how to start, that is, the entry point. So let’s use the log at the beginning as an example to find this entry point
If you take a closer look at the output log, you’ll see that there is one important line in the log before the local service is exposed
Service ready on spring started. Service: com. Alibaba. Dubbo. Demo. DemoService, dubbo version: 2.0.0, current host: 127.0.0.1
We use the compiler’s search text function to locate the ServiceBean class. What does this class do? Well, I assume I don’t know either, and since I don’t know, let’s look at his succession diagram
From this diagram we can see a lot about Spring, and an important interface is the ApplicationListener. In order to be sensitive to this key interface, one must first understand Spring, which is the Event mechanism of Spring. What is the event mechanism? For example, listen for spring container initialization to complete. So let’s locate this line of logs, debug down
Now it’s time to start tapping on the blackboard and highlighting.
Properties file. It seems that I have not set it at all. Besides, can I change the name of the file? Faced with such a question, I would never tell him the answer directly. Instead, I would tell him how I got the answer, as shown in the picture below
For log4j.xml, it’s like I’ve never written code to load it. Why would it load it
Moving on, here is our second interview question
Why is this traversal going on here, because Dubbo supports multiple protocols, right
Dubbo supports multiple protocols. By default, the dubbo protocol is used
Without further ado, here comes the third interview question, which is also the focus of the service release, local exposure and remote exposure
Why is there local exposure and remote exposure? There is no point in discussing technology without considering the scenario. In Dubbo, a service may be both a Provider and a Consumer, so it may call its own service. If it accesses the service through the network, it will naturally neglect the near and seek the far. Therefore, it has the design of locally exposed service. That’s how we know the difference between the two
Local exposure is exposure to the JVM and does not require network communication.
Remote exposure exposes information such as IP addresses and ports to remote clients, requiring network communication.
This article focuses on the overall process of service publishing, with more details and summaries to follow. Let’s forget — actually, if you look at my screenshots, I’m going to take the class name and the method name so that you can locate it quickly.
As you can see from the figure above, Adaptive is used (which is very important and will be explained in a follow-up article). Click ProxyFactory to view the source code
Adaptive annotation is a distinction between classes and methods. (It is also popular to ask questions about this distinction in interviews. Leave this to the Adaptive topic ), which generates dynamically compiled Adaptive classes. The following is a look at the source code of dynamically compiled Adaptive classes
The first step is to set the log4j level to DEBUG
Why do you need to adjust DEBUG? More importantly, tell everyone how to know it, as shown in the following picture. Of course, at this time, friends may say, I don’t know this class and still can’t find this line of code. As a matter of fact, this will also be mentioned in the later special Adaptive, and I will provide another implementation idea then, so that we can think and compare the advantages and disadvantages together.
After opening DEBUG, we will restart the log and see the following output. This is the relevant code. We will create a new file according to the package name, as follows
Let’s set a breakpoint on the getInvoker method and restart it.
As you can see from the above figure, the url for local exposure starts with injvm. Let’s take a look at remote exposure. The interview answer is not a perfect answer, but from some of the details, to see whether a person has really studied the source code.
Going back to the beginning,dubbo naming is very formal. From the Wrapper name, it can be linked to Spring’s Bean Wrapper and decorator design pattern. Also look at the coding conventions in the documentation
The getInvoker method is referred to above, and if you notice from the documentation at the beginning of this article that the key to Dubbo handling service exposure is that Invoker is switched to Exporter In fact, there are still a lot of details to be continued, but because this article has a certain amount of space, so I can only see you next week.
Author: fat the link: https://www.jianshu.com/p/60a9263f2ee2
This number has opened the following 20 topics, after attention to view [my home page], review related topics!
【 Introduction to Minimalism 】【 Dubbo Combat 】
Dubbo source Code Topic
【 data Structure 】【 Netty source code 】
【 Network Protocol topic 】【 Spring source code topic 】
【 Concurrent Programming topics 】【 Springboot Topics 】
【 Architecture Technology Topics 】【 ZooKeeper Topics 】
【BATj Interview Topics 】【 Redis Combat Topics 】
【 mQ Middleware Topic 】【mysql optimization topic 】
【grpc+etcd专题】【 线程相关专题】
【JVM Tuning Topic 】【 SpringCloud Topic 】
Down, down, down, down, down
Click a like and leave a message before you leave