Home >Java >JavaInterview questions >Java interview questions-Dubbo

Java interview questions-Dubbo

王林
王林forward
2020-10-28 16:26:482628browse

Java interview questions-Dubbo

Contents

(Video tutorial recommendation: java course)

1. Dubbo interview questions

2.Dubbo interview question answers analysis

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 any other options?

4. Services Is the call blocking?

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

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

7. What is the principle behind the failure kicking of service providers?

8. How can the service go online without affecting 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 I directly connect to a certain service when there are multiple registrations for the same service?

13. Draw a flow chart of service registration and discovery?

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

15. Dubbo service is downgraded. How to retry after failure?

16. What problems did you encounter when using Dubbo?

17. Dubbo Monitor implementation principle?

18. What design patterns does Dubbo use?

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

20. What is the difference between Dubbo SPI and Java SPI?

21. Does Dubbo support distributed transactions?

22. Can Dubbo cache results?

23. How can the service be compatible with old versions when it is online?

24. What are the packages that Dubbo must depend on?

25. What can the Dubbo telnet command do?

26. Does Dubbo support service downgrade?

27. How does Dubbo shut down gracefully?

28. What is the difference between Dubbo and Dubbox?

29. What is the difference between Dubbo and Spring Cloud?

30. Do you know other distributed frameworks?

3. The difference between Spring Cloud and Dubbo

4. Another microservice framework SpringCloud

SpringCloud component principle: Eureka, Feign, Ribbon, Hystrix, Zuul


1.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 any other options?

4. Services Is the call blocking?

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

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

7. What is the principle behind the failure kicking of service providers?

8. How can the service go online without affecting 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 I directly connect to a certain service when there are multiple registrations for the same service?

13. Draw a flow chart of service registration and discovery?

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

15. Dubbo service is downgraded. How to retry after failure?

16. What problems did you encounter when using Dubbo?

17. Dubbo Monitor implementation principle?

18. What design patterns does Dubbo use?

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

20. What is the difference between Dubbo SPI and Java SPI?

21. Does Dubbo support distributed transactions?

22. Can Dubbo cache results?

23. How can the service be compatible with old versions when it is online?

24. What are the packages that Dubbo must depend on?

25. What can the Dubbo telnet command do?

26. Does Dubbo support service downgrade?

27. How does Dubbo shut down gracefully?

28. What is the difference between Dubbo and Dubbox?

29. What is the difference between Dubbo and Spring Cloud?

30. Do you know other distributed frameworks?

2.Dubbo interview question answer analysis

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. Service-oriented architecture (SOA) was born, and thus derived A series of corresponding technologies, such as a service framework that encapsulates service provision, service invocation, connection processing, communication protocols, serialization methods, service discovery, service routing, log output and other behaviors. In this way, the service governance framework for distributed systems emerged, 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, based on the business of provider and consumer Design the corresponding interface and implementation

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

Service proxy layer (Proxy): Transparent proxy of the service interface, which generates the client Stub and the server Skeleton of the service, with ServiceProxy as the center, and the extended interface is ProxyFactory

Service registration layer (Registry): Encapsulation service address Registration and discovery, centered on service URL, extended interfaces are RegistryFactory, Registry, RegistryService

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

Monitoring layer (Monitor): RPC call number and call time monitoring, with Statistics as the center, extended The interfaces are MonitorFactory, Monitor and MonitorService

Remote call layer (Protocal):Encapsulates RPC calls, centered on Invocation and Result, and the extended interfaces are Protocol, Invoker and Exporter

Information exchange layer (Exchange): Encapsulation request response mode, synchronous to asynchronous. Centered on Request and Response, the extended interfaces are Exchanger, ExchangeChannel, ExchangeClient and ExchangeServer

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

Data serialization layer (Serialize):Some reusable tools, the extended interfaces are Serialization, ObjectInput, ObjectOutput and ThreadPool

3. What communication framework is used by default? Are there any other options?

The netty framework and mina are also recommended by default.

4. Is the service call blocking?

The default is blocking and can be called asynchronously. If there is no return value, you can do this. 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 multi-threading, the overhead is smaller, and asynchronous calls will return a Future object.

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

It is recommended to use Zookeeper as the registration center, as well as Redis, Multicast, and Simple registration centers, but they are not recommended.

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

It is recommended to use Hessian serialization, as well as Duddo, FastJson, and Java's own serialization.

7. What is the principle behind the failure kicking of service providers?

Service failure kicks out the temporary node principle based on zookeeper.

8. How can the service go online without affecting the old version?

Using multi-version development without affecting old versions.

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

Can be combined with zipkin to implement distributed service tracking.

10. What are the core configurations?

11. What protocol does Dubbo recommend?

#12. Can I directly connect to a certain service if there are multiple registrations for the same service?

You can directly connect point-to-point, just modify the configuration, or you can directly connect to a service through telnet.

(Recommendations for more related interview questions: java interview questions and answers)

13. Draw a flow chart of service registration and discovery?

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

#15. Dubbo service is downgraded. How to retry after failure?

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

16. What problems did you encounter when using Dubbo?

The corresponding service cannot be found in the registration center. Check whether the service implementation class has added the @service annotation. Unable to connect to the registration center, check whether the corresponding test IP in the configuration file is correct

17 , Dubbo Monitor implementation principle?

The consumer side will first go through the filter chain before initiating the call; the provider side will also go through the filter chain first when receiving the request, and then perform the actual business logic processing. By default, there is a Monitorfilter in both the consumer and provider filter chains.

1. MonitorFilter sends data to DubboMonitor

2. DubboMonitor aggregates the data (statistics in 1min are aggregated by default) and temporarily stores them in ConcurrentMap statisticsMap, and then uses a The thread pool containing 3 threads (thread name: DubboMonitorSendTimer) calls SimpleMonitorService every 1 minute to traverse and send the statistical data in the statisticsMap. After each one is sent, the AtomicReference of the current Statistics is reset

3. SimpleMonitorService Stuff 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 uses an infinite loop Written in the form)

5. SimpleMonitorService will also use a thread pool containing 1 thread (thread name: DubboMonitorTimer) to draw the statistical data in the file into a chart every 5 minutes

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.

Factory Mode

Provider will call the export method of ServiceConfig when exporting a service. There is a field in ServiceConfig:

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

Dubbo has a lot of this code. This is also a factory pattern, but the implementation class is obtained using the JDKSPI mechanism. The advantage of this implementation is that it is highly scalable. If you want to extend the implementation, you only need to add a file to the classpath, and there is zero code intrusion. In addition, like the Adaptive implementation above, it is possible to dynamically decide which implementation to call when calling. However, because this implementation uses a dynamic proxy, it will make code debugging more troublesome, and it is necessary to analyze the actual called implementation class.

Decorator Pattern

Dubbo 在启动和调用阶段都大量使用了装饰器模式。以 Provider 提供的调用链为例,具体的调用链代码是在 ProtocolFilterWrapper 的 buildInvokerChain 完成的,具体是将注解中含有 group=provider 的 Filter 实现,按照 order 排序,最后的调用顺序是:

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

更确切地说,这里是装饰器和责任链模式的混合使用。例如,EchoFilter 的作用是判断是否是回声测试请求,是的话直接返回内容,这是一种责任链的体现。而像ClassLoaderFilter 则只是在主功能上添加了功能,更改当前线程的 ClassLoader,这是典型的装饰器模式。

 观察者模式

Dubbo 的 Provider 启动时,需要与注册中心交互,先注册自己的服务,再订阅自己的服务,订阅时,采用了观察者模式,开启一个 listener。注册中心会每 5 秒定时检查是否有服务更新,如果有更新,向该服务的提供者发送一个 notify 消息,provider 接受到 notify 消息后,运行 NotifyListener 的 notify 方法,执行监听器方法。

 动态代理模式

Dubbo 扩展 JDK SPI 的类 ExtensionLoader 的 Adaptive 实现是典型的动态代理实现。Dubbo 需要灵活地控制实现类,即在调用阶段动态地根据参数决定调用哪个实现类,所以采用先生成代理类的方法,能够做到灵活的调用。生成代理类的代码是 ExtensionLoader 的 createAdaptiveExtensionClassCode 方法。代理类主要逻辑是,获取 URL 参数中指定参数的值作为获取实现类的 key。

19、Dubbo 配置文件是如何加载到 Spring 中的?

Spring 容器在启动的时候,会读取到 Spring 默认的一些 schema 以及 Dubbo 自定义的 schema,每个 schema 都会对应一个自己的 NamespaceHandler,NamespaceHandler 里面通过 BeanDefinitionParser 来解析配置信息并转化为需要加载的 bean 对象!

20、Dubbo SPI 和 Java SPI 区别?

JDK SPI:

JDK 标准的 SPI 会一次性加载所有的扩展实现,如果有的扩展吃实话很耗时,但也没用上,很浪费资源。所以只希望加载某个的实现,就不现实了

 DUBBO SPI:

1、对 Dubbo 进行扩展,不需要改动 Dubbo 的源码

2、延迟加载,可以一次只加载自己想要加载的扩展实现。

3、增加了对扩展点 IOC 和 AOP 的支持,一个扩展点可以直接 setter 注入其

它扩展点。

4、Dubbo 的扩展机制能很好的支持第三方 IoC 容器,默认支持 Spring Bean。

21、Dubbo 支持分布式事务吗?

目前暂时不支持,可与通过 tcc-transaction 框架实现

介绍:tcc-transaction 是开源的 TCC 补偿性分布式事务框架

TCC-Transaction 通过 Dubbo 隐式传参的功能,避免自己对业务代码的入侵。

22、Dubbo 可以对结果进行缓存吗?

为了提高数据访问的速度。Dubbo 提供了声明式缓存,以减少用户加缓存的工作量

其实比普通的配置文件就多了一个标签 cache="true"

23、服务上线怎么兼容旧版本?

可以用版本号(version)过渡,多个不同版本的服务注册到注册中心,版本号不同的服务相互间不引用。这个和服务分组的概念有一点类似。

24、Dubbo 必须依赖的包有哪些?

Dubbo 必须依赖 JDK,其他为可选。

25、Dubbo telnet 命令能做什么?

dubbo 服务发布之后,我们可以利用 telnet 命令进行调试、管理。Dubbo2.0.5 以上版本服务提供端口支持 telnet 命令

连接服务

telnet localhost 20880 //键入回车进入 Dubbo 命令模式。

查看服务列表

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

· ls (list services and methods)

· ls : 显示服务列表。

· ls -l : 显示服务详细信息列表。

· ls XxxService:显示服务的方法列表。

· ls -l XxxService: Displays a list of service method details.

26. Does Dubbo support service downgrade?

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

27. How does Dubbo shut down gracefully?

Dubbo uses JDK's ShutdownHook to complete graceful shutdown. Therefore, if you use kill -9 PID and other forced shutdown instructions, graceful shutdown will not be executed. It will only be executed when kill PID is used.

28. What is the difference between Dubbo and Dubbox?

Dubbox is an extension project made by Dangdang based on Dubbo after Dubbo stopped maintaining. For example, it added services that can be called by Restful, updated open source components, etc.

29. What is the difference between Dubbo and Spring Cloud?

Based on the various elements of the microservice architecture, let’s see what support Spring Cloud and Dubbo provide.

The microservice architecture built using Dubbo is like assembling a computer. We have a high degree of freedom of choice in each link, but the final result is likely to be due to poor quality of a memory. It always makes people feel uneasy if it turns off, but if you are an expert, then these are not problems; and Spring Cloud is like a brand machine. Under the integration of Spring Source, it has done a lot of compatibility tests to ensure The machine has higher stability, but if you want to use something other than non-original components, you need to have a sufficient understanding of its basics.

30. Do you know other distributed frameworks?

Others include spring's spring cloud, facebook's thrift, twitter's finagle, etc.

3. The difference between Spring Cloud and Dubbo

##Dubbo-monitorSpring Boot Admin##Data flowNoneSpring Cloud Stream##Batch Task##......The biggest difference :Spring Cloud abandons Dubbo's RPC communication and adopts HTTP-based REST method. Strictly speaking, both methods have their own pros and cons. Although to a certain extent, the latter sacrifices the performance of service calls, it also avoids the problems caused by native RPC mentioned above. Moreover, REST is more flexible than RPC. The service provider and the caller only rely on a contract, and there is no strong dependence at the code level. This is more appropriate in a microservice environment that emphasizes rapid evolution. 4. Another microservice framework SpringCloudSpringCloud component principles: Eureka, Feign, Ribbon, Hystrix, Zuul

Dubbo

Spring Cloud

Service Registration Center

Zookeeper

Spring Cloud Netflix Eureka

Service Calling method

##RPC

##Circuit breaker

Imperfect

Spring Cloud Netflix Hystrix

Service Gateway

None

Spring Cloud Netflix Zuul

Distributed Configuration

None

Spring Cloud Config

Service Tracking

None

##Spring Cloud Sleuth

##Message Bus

None

Spring Cloud Bus

None

Spring Cloud Task

......

......

Please read the previous issues:

Related recommendations:

Getting started with java

The above is the detailed content of Java interview questions-Dubbo. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete