30 high-frequency interview questions for Dubbo in 2020! Still worrying about the interview, come and take a look!

Preface

Dubbo is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation solutions and SOA service governance solutions. Simply put, dubbo is a service framework. If there is no distributed requirement, it is actually unnecessary. Only when it is distributed, there is a requirement for a distributed service framework like dubbo, and it is essentially a service call Dongdong, to put it bluntly, it is a distributed framework for remote service invocation (say goodbye to WSdl in the Web Service mode and register on dubbo in the manner of service providers and consumers).

Insert picture description here

Many times, when we actually use this technology, it may be because of the needs of the project, so we use it. However, as to why we need to use this technology, we may not know very well by ourselves, but in fact, we understand the technology. Origin and background knowledge are still helpful for understanding a technology.

Knowledge about Dubbo summarizes a mind map

Insert picture description here

Dubbo interview questions

1. Why use Dubbo?

2. What are the layers of Dubbo's overall architecture design?

3. What communication framework is used by default, are there other options?

4. Is the service call blocking?

5. What registration center is generally used? Are there other options?

6. What serialization framework is used by default, and what else do you know?

7. What is the principle that the service provider can achieve the failure kick-out?

8. Why does the service launch not affect the old version?

9. How to solve the problem of too long service call chain?

10. What are the core configurations?

11. What protocol does Dubbo recommend?

12. Can a service be directly connected to the same service when multiple registrations are made?

13. Draw a flowchart of service registration and discovery?

14. How many solutions are available for Dubbo cluster fault tolerance?

15. Dubbo service is downgraded, what should I do if I fail to retry?

16. What problems did you encounter during the use of Dubbo?

17. How does Dubbo Monitor work?

18. What design patterns does Dubbo use?

19. How is the Dubbo configuration file loaded into Spring?

20. The difference between Dubbo SPI and Java SPI?

21. Does Dubbo support distributed transactions?

22. Can Dubbo cache the results?

23. How is the service online compatible with the old version?

24. What packages must Dubbo depend on?

25. What can the Dubbo telnet command do?

26. Does Dubbo support service downgrade?

27. How does Dubbo stop gracefully?

28. The difference between Dubbo and Dubbox?

29. The difference between Dubbo and Spring Cloud?

30. Do you know other distributed frameworks?

Insert picture description here The following is an analysis of Dubbo interview questions

1. Why use Dubbo?

With the further development of servitization, there are more and more services, and the calls and dependencies between services are becoming more and more complex. The service-oriented architecture (SOA) was born, and a series of corresponding technologies were derived from this. Such as a service framework that encapsulates behaviors such as service provision, service invocation, connection processing, communication protocol, serialization method, service discovery, service routing, log output, etc. In this way, a service governance framework for distributed systems appeared, and Dubbo was born.

2. What are the layers of Dubbo's overall architecture design?

Interface service layer (Service): This layer is related to business logic, and the corresponding interface and implementation are designed according to the business design of provider and consumer

Configuration layer (Config): External configuration interface, centered on ServiceConfig and ReferenceConfig

Service proxy layer (Proxy): transparent proxy for the service interface, generating the client Stub of the service and the Skeleton of the server, centered on ServiceProxy, and the extended interface is ProxyFactory

Service registration layer (Registry): Encapsulates the registration and discovery of service addresses, centered on the service URL, and the extended interfaces are RegistryFactory, Registry, and RegistryService

Routing layer (Cluster): Encapsulates routing and load balancing of multiple providers, and bridges the registry, with Invoker as the center, and the extended interfaces are Cluster, Directory, Router and LoadBlancce

Monitoring layer (Monitor): RPC call times and call time monitoring, centered on Statistics, and extended interfaces are MonitorFactory, Monitor and MonitorService

Remote call layer (Protocal): encapsulates RPC calls, centered on Invocation and Result, and extended interfaces for Protocal, Invoker and Exporter

Information exchange layer (Exchange): encapsulate the request response mode, synchronous to asynchronous. With Request and Response as the center, the extended interfaces are Exchanger, ExchangeChannel, ExchangeClient and ExchangeServer

Network Transport Layer (Transport): Abstract mina and netty are unified interfaces, centered on Message, and extended interfaces are Channel, Transporter, Client, Server and Codec

Data serialization layer (Serialize): Some reusable tools, with extended interfaces such as Serialization, ObjectInput, ObjectOutput and ThreadPool

3. What communication framework is used by default, are there other options?

The netty framework and mina are also recommended by default.

4. Is the service call blocking?

The default is blocking, you can call asynchronously, you can do this if there is no return value. Dubbo is a non-blocking implementation of parallel calls based on NIO. The client does not need to start multiple threads to complete parallel calls to multiple remote services. Compared with multithreading, the overhead is small. Asynchronous calls will return a Future object.

5. What registration center is generally used? Are there other options?

It is recommended to use Zookeeper as the registry, as well as Redis, Multicast, and Simple registry, but not recommended.

6. What serialization framework is used by default, and what else do you know?

It is recommended to use Hessian serialization, and Duddo, FastJson, and Java have their own serialization.

7. What is the principle that the service provider can achieve the failure kick-out?

Service failure kicked out based on zookeeper's principle of temporary nodes.

8. Why does the service launch not affect the old version?

Multi-version development is adopted, and the old version is not affected.

9. How to solve the problem of too long service call chain?

Can be combined with zipkin to achieve distributed service tracking.

10. What are the core configurations?

Insert picture description here

11. What protocol does Dubbo recommend?

Insert picture description here

12. Can a service be directly connected to the same service when multiple registrations are made?

It can be directly connected point-to-point, and the configuration can be modified, or a certain service can be directly connected via telnet.

13. Draw a flowchart of service registration and discovery?

Insert picture description here 14. How many solutions are available for Dubbo cluster fault tolerance?

Insert picture description here

15. Dubbo service is downgraded, what should I do if I fail to retry?

You can set mock="return null" in dubbo:reference. The value of mock can also be modified to true, and then implement a Mock class under the same path as the interface. The naming rule is "interface name + Mock" suffix. Then implement your own downgrade logic in the Mock class

16. What problems did you encounter during the use of Dubbo?

Cannot find the corresponding service in the registry, check whether the service implementation class has added the @service annotation, and cannot connect to the registry, check whether the corresponding test ip in the configuration file is correct

17. How does Dubbo Monitor work?

The consumer side will go through the filter chain before initiating the call; the provider side will go through the filter chain first when receiving the request, and then the real business logic processing will be performed. By default, there will be a Monitorfilter in the filter chain of the consumer and provider.

  1. MonitorFilter sends data to DubboMonitor
  2. DubboMonitor aggregates the data (by default, aggregates the statistics in 1min) and temporarily stores it in ConcurrentMap<Statistics, AtomicReference> statisticsMap, and then uses a thread pool with 3 threads (thread name: DubboMonitorSendTimer) to call SimpleMonitorService to traverse every 1 minute Send statistics data in statisticsMap, reset the current Statistics AtomicReference every time one is sent
  3. SimpleMonitorService stuffs these aggregated data into the BlockingQueue queue (the queue is capitalized as 100000)
  4. SimpleMonitorService uses a background thread (thread name: DubboMonitorAsyncWriteLogThread) to write the data in the queue to the file (the thread writes in an endless loop)
  5. SimpleMonitorService will also use a thread pool containing 1 thread (thread name: DubboMonitorTimer) every 5 minutes to draw the statistical data in the file into a graph

18. What design patterns does Dubbo use?

Dubbo framework uses a variety of design patterns in the initialization and communication process, which can flexibly control functions such as class loading and permission control. When the factory mode Provider exports services, it will call the export method of ServiceConfig. There is a field in ServiceConfig:

private static final Protocol protocol =
ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtensi
on();

There are many such codes in Dubbo. This is also a factory model, but the acquisition of the implementation class uses the JDKSPI mechanism. The advantage of this implementation is strong scalability. If you want to expand the implementation, you only need to add a file under the classpath, and the code is zero intrusion. In addition, like the Adaptive implementation above, it is possible to dynamically determine which implementation to call when calling, but because this implementation uses a dynamic proxy, it will cause troublesome code debugging, and it is necessary to analyze the implementation class actually called.

The decorator mode Dubbo makes extensive use of the decorator mode during the startup and invocation phases. Take the call chain provided by Provider as an example. The specific call chain code is completed in the buildInvokerChain of ProtocolFilterWrapper. Specifically, it implements the Filter with group=provider in the annotation and sorts it by order. The final call sequence is:

EchoFilter -> ClassLoaderFilter -> GenericFilter -> ContextFilter ->
ExecuteLimitFilter -> TraceFilter -> TimeoutFilter -> MonitorFilter ->
ExceptionFilter

More precisely, here is a mixed use of decorators and chain of responsibility patterns. For example, the function of EchoFilter is to determine whether it is an echo test request, and if it is, the content is returned directly, which is a manifestation of a chain of responsibility. And like ClassLoaderFilter, it only adds a function to the main function, changing the ClassLoader of the current thread, which is a typical decorator pattern.

Observer mode

When Dubbo's Provider starts, it needs to interact with the registration center, first register its own service, and then subscribe to its own service. When subscribing, it adopts the observer mode and starts a listener. The registry will regularly check whether there is a service update every 5 seconds. If there is an update, it sends a notify message to the service provider. After the provider receives the notify message, it runs the notify method of NotifyListener and executes the listener method.

Dynamic proxy mode

The Adaptive implementation of Dubbo's extension JDK SPI class ExtensionLoader is a typical dynamic proxy implementation. Dubbo needs to flexibly control the implementation class, that is, dynamically decide which implementation class to call according to the parameters in the call phase, so the method of first generating the proxy class can be used flexibly. The code to generate the proxy class is the createAdaptiveExtensionClassCode method of ExtensionLoader. The main logic of the proxy class is to obtain the value of the specified parameter in the URL parameter as the key to obtain the implementation class.

19. How is the Dubbo configuration file loaded into Spring?

When the Spring container starts, it will read some of Spring's default schemas and Dubbo's custom schemas. Each schema corresponds to its own NamespaceHandler. The NamespaceHandler uses BeanDefinitionParser to parse the configuration information and convert it into bean objects that need to be loaded!

Insert picture description here

20. The difference between Dubbo SPI and Java SPI?

JDK SPI: JDK standard SPI will load all the extension implementations at once. If some extensions are really time-consuming, they are useless and waste resources. So just hope to load a certain implementation, it is not realistic DUBBO SPI:

1. Extend Dubbo without changing Dubbo's source code

2. Lazy loading, you can load only the extension implementation you want to load at a time.

3. Added support for extension point IOC and AOP, one extension point can directly setter into other extension points.

4. Dubbo's extension mechanism can well support third-party IoC containers, and Spring Bean is supported by default.

21. Does Dubbo support distributed transactions?

It is not currently supported, but can be introduced through the tcc-transaction framework: tcc-transaction is an open source TCC compensating distributed transaction framework TCC-Transaction uses Dubbo's implicit parameter transfer function to avoid intrusion into business code.

22. Can Dubbo cache the results?

In order to improve the speed of data access. Dubbo provides declarative caching to reduce the workload of users adding caching. <dubbo:reference cache="true" /> In fact, there is one more tag cache="true" than the normal configuration file.

23. How is the service online compatible with the old version?

You can use the version number (version) to transition, multiple services of different versions are registered to the registry, and services with different version numbers do not reference each other. This is similar to the concept of service grouping.

24. What packages must Dubbo depend on?

Dubbo must rely on JDK, others are optional.

25. What can the Dubbo telnet command do?

After the dubbo service is released, we can use the telnet command for debugging and management. Dubbo 2.0.5 and above services provide port support telnet command connection service telnet localhost 20880 //Type enter to enter Dubbo command mode. View service list

dubbo>ls
com.test.TestService
dubbo>ls com.test.TestService
create
delete
query

· Ls (list services and methods) · ls: Display a list of services. · Ls -l: Display a list of service details. · Ls XxxService: Display the method list of the service. · Ls -l XxxService: Display the detailed information list of service methods.

26. Does Dubbo support service downgrade?

To set mock="return null" in dubbo:reference. The value of mock can also be modified to true, and then implement a Mock class under the same path as the interface. The naming rule is "interface name + Mock" suffix. Then implement your own downgrade logic in the Mock class

27. How does Dubbo stop gracefully?

Dubbo uses the ShutdownHook of the JDK to complete the graceful shutdown. Therefore, if you use a forced shutdown command such as kill -9 PID, the graceful shutdown will not be executed. It will only be executed when the kill PID is passed. 28. The difference between Dubbo and Dubbox?

Dubbox is an extension project made by Dangdang based on Dubbo after Dubbo ceased maintenance, such as adding services that can be called by Restful, and updating open source components.

29. The difference between Dubbo and Spring Cloud?

According to the various elements of the microservice architecture, see what support Spring Cloud and Dubbo provide.

Insert picture description here

The microservice architecture built with Dubbo is like assembling a computer. We have a high degree of freedom in each link, but the final result is likely to be unlit because of the poor quality of the memory, which always makes people feel uneasy, but if you If you are a master, then these are not problems; and Spring Cloud is like a branded machine. Under the integration of Spring Source, a lot of compatibility tests have been done to ensure that the machine has higher stability, but if you want to use non- For things other than the original components, you need to have a sufficient understanding of its basics.

30. Do you know other distributed frameworks?

Others include spring cloud of spring, thrift of facebook, finagle of twitter, etc.

file

Guess you like

Origin blog.csdn.net/weixin_46577306/article/details/107416184