1. What is Dubbo?
- Dubbo is a distributed, high-performance, and transparent RPC service framework that provides efficient service management solutions such as automatic service registration and automatic discovery, and can be seamlessly integrated with the Spring framework.
- Documentation
2. Why do we need service governance?
- Too many service URLs are difficult to configure
- Clusters also need to be deployed when the load balance distribution node is under excessive pressure
- Service dependencies are chaotic and the startup sequence is not clear
- Too many services make it difficult to analyze performance indicators and need to be monitored
3. What are the main application scenarios of Dubbo?
- The transparent remote method call is just like calling a local method to call a remote method, only simple configuration, no API intrusion.
- The soft load balancing and fault tolerance mechanism can replace hardware load balancers such as F5 in the intranet, reducing costs and reducing single points.
- Automatic registration and discovery of services, no need to write down the address of the service provider, the registration center queries the IP address of the service provider based on the interface name, and can smoothly add or delete service providers.
4. What is the core function of Dubbo?
Mainly are the following 3 core functions:
- Remoting: A network communication framework that provides abstract encapsulation of a variety of NIO frameworks, including information exchange methods in "synchronous to asynchronous" and "request-response" modes.
- Cluster: A service framework that provides transparent remote procedure calls based on interface methods, including multi-protocol support, and cluster support such as soft load balancing, failure tolerance, address routing, and dynamic configuration.
- Registry: Service registration, based on the directory service of the registry, enables service consumers to dynamically find service providers, makes addresses transparent, and enables service providers to smoothly add or reduce machines.
4. What is the core component of Dubbo?
Component | Description |
---|---|
Provider | Service provider of exposed service |
Consumer | Service consumer calling remote service |
Registry | Registry for service registration and discovery |
Monitor | Monitoring center that counts the number of service calls and call time |
Container | Service running container |
5. What is the process of Dubbo service registration and discovery?
Flow Description:
- Provider binds the specified port and starts the service
- The provider connects to the registry, and sends the local IP, port, application information and service information to the registry for storage
- Consumer, connect to the registration center, and send application information and requested service information to the registration center
- The registration center matches the provider list corresponding to the service information requested by the consumer and sends it to the Consumer application cache.
- When the Consumer initiates a remote call, it selects one of them to initiate the call based on the cached consumer list.
- Provider status changes will be notified to the registry in real time, and pushed to Consumer in real time from the registry
Reason for design:
- Consumer and Provider are decoupled, and both parties can increase or decrease the number of nodes horizontally.
- The registration center can do a peer-to-peer cluster for itself, and can dynamically add or remove nodes, and after any one is down, it will automatically switch to another
- Decentralization, the two parties do not directly rely on the registry, even if the registry is all down for a short time, it will not affect the call of the service
- The service provider is stateless, after any one of them goes down, it will not affect the use
6. The architecture design of Dubbo?
The Dubbo frame design is divided into 10 layers:
service
Service interface layer: This layer is related to the actual business logic, and the corresponding interface and implementation are designed according to the business of the service provider and the service consumer.config
Configuration layer: External configuration interface, with ServiceConfig and ReferenceConfig as the center, can directly initialize configuration classes, or generate configuration classes through spring analysisproxy
Service proxy layer: transparent proxy of service interface, generating service client Stub and server side Skeleton, centered on ServiceProxy, extended interface is ProxyFactoryregistry
Registration center layer: encapsulates the registration and discovery of service addresses, centered on the service URL, and the extension interfaces are RegistryFactory, Registry, RegistryServicecluster
Routing layer: Encapsulate routing and load balancing of multiple providers, and bridge the registry, centered on Invoker, with extended interfaces as Cluster, Directory, Router, LoadBalancemonitor
Monitoring layer: Monitoring of the number of RPC calls and call time, centered on Statistics, with extended interfaces as MonitorFactory, Monitor, MonitorServiceprotocol
Remote call layer: encapsulate RPC calls, centered on Invocation and Result, and extended interfaces as Protocol, Invoker, and Exporterexchange
Information exchange layer: Encapsulate the request response mode, synchronous to asynchronous, with Request and Response as the center, and the extended interfaces are Exchanger, ExchangeChannel, ExchangeClient, ExchangeServertransport
Network transport layer: abstract mina and netty as unified interfaces, with Message as the center, and extended interfaces as Channel, Transporter, Client, Server, Codecserialize
Data serialization layer: some reusable tools, the extended interface is Serialization, ObjectInput, ObjectOutput, ThreadPool
7. What is the service calling process of Dubbo?
8. Dubbo's registry cluster is down. Can publishers and subscribers still communicate?
Yes, when dubbo is started, consumers will pull the registered producer's address interface and other data from zookeeper and cache it locally. each
9. The relationship between Dubbo and Spring?
Dubbo adopts the all-Spring configuration method, transparent access to the application, without any API intrusion to the application, just use Spring to load the Dubbo configuration, and Dubbo is loaded based on Spring's Schema extension.
10. What communication framework does Dubbo use?
Use NIO Netty framework by default
11. What load balancing strategies does Dubbo cluster provide?
Random LoadBalance
: Random selection of provider strategy is conducive to dynamic adjustment of provider weight. The cross-section collision rate is high, and the more calls, the more even the distribution;RoundRobin LoadBalance
: Round-robin selection of provider strategy, evenly distributed, but there is a problem of request accumulation;LeastActive LoadBalance
: The least active call strategy to solve the problem that slow providers receive fewer requests;ConstantHash LoadBalance
: Consistent Hash strategy, so that the same parameter request is always sent to the same provider, and one machine is down. It can be allocated to other providers based on virtual nodes to avoid drastic changes in providers;
缺省时为Random随机调用
12. What are Dubbo's cluster fault tolerance solutions?
Failover Cluster
: Automatically switch after failure. When failure occurs, try another server again. Usually used for read operations, but retrying will bring longer delays.Failfast Cluster
: Fail fast, only initiate one call, and report an error immediately if it fails. Usually used for non-idempotent write operations, such as adding records.Failsafe Cluster
: Fail safe, when an exception occurs, just ignore it. Usually used for operations such as writing to the audit log.Failback Cluster
: Failure automatic recovery, background recording of failed requests, and regular retransmission. Usually used for message notification operations.Forking Cluster
: Call multiple servers in parallel and return as long as one succeeds. It is usually used for read operations with high real-time requirements, but more service resources are wasted. The maximum number of parallels can be set by forks="2".Broadcast Cluster
: Call all providers by broadcast, call them one by one, and report an error if any one reports an error. Usually used to notify all providers to update local resource information such as caches or logs.
13. Dubbo's default cluster fault tolerance solution?
Failover Cluster
14. What protocols does Dubbo support, the application scenarios of each protocol, the advantages and disadvantages?
dubbo
: Single long connection and NIO asynchronous communication, suitable for large concurrent service calls with small data volume, and consumers are much larger than providers. Transmission protocol TCP, asynchronous, Hessian serialization;rmi
: Use the JDK standard rmi protocol implementation, the transmission parameters and return parameter objects need to implement the Serializable interface, use the java standard serialization mechanism, use the blocking short connection, the transmission data packet size is mixed, the number of consumers and providers is almost the same, and the transmission File, transfer protocol TCP. Multiple short connections, TCP protocol transmission, synchronous transmission, suitable for conventional remote service calls and rmi interoperation. In the Common-Collections package that relies on a lower version, java serialization has security vulnerabilities;webservice
: Remote call protocol based on WebService, integrated CXF implementation, providing interoperability with native WebService. Multiple short connections, based on HTTP transmission, synchronous transmission, suitable for system integration and cross-language calls;http
: The remote invocation protocol based on Http form submission is implemented using Spring's HttpInvoke. Multiple short connections, transmission protocol HTTP, mixed input parameter size, more providers than consumers, need to be called by the application and browser JS;hessian
: Integrate Hessian service, based on HTTP communication, use Servlet to expose service, Dubbo embeds Jetty as the server by default, and provides interoperability with Hession service. Multiple short connections, synchronous HTTP transmission, Hessian serialization, large incoming parameters, the provider is larger than the consumer, the provider is under greater pressure, and files can be transferred;memcache
: RPC protocol based on memcachedredis
: RPC protocol based on redis implementation
15. What protocol does Dubbo recommend?
Use dubbo protocol by default
16. Which registration centers does Dubbo have?
Multicast
Registration Center: Multicast registration center does not require any central node, as long as it broadcasts the address, service registration and discovery can be carried out. Realization based on multicast transmission in the network;Zookeeper
Registration Authority: Zookeeper based distributed coordination system implemented using the Zookeeperwatch 机制
for data changes;redis
Registration Authority: redis-based implementation, the use ofkey/Map
storage, storage services to key names and types, Map the key storage service URL, value service expiration time.发布/订阅模式
Notification data changes based on redis ;Simple
Registry
17. Dubbo uses the registry by default?
Adopt Zookeeper
18. What serialization methods does Dubbo support?
Hessian serialization is used by default, and Duddo, FastJson, and Java come with serialization.
19. How to set Dubbo timeout time?
There are two ways to set Dubbo timeout time:
- The service provider sets the timeout period. In Dubbo's user documentation, it is recommended to configure as much as possible if you can configure more on the server side, because the service provider knows the characteristics of the service better than the consumer.
- The service consumer side sets the timeout time. If the timeout time is set on the consumer side, the consumer side is the main one, that is, the priority is higher. Because the service caller has more flexible control over setting the timeout period. If the consumer times out, the server thread will not be customized and a warning will be generated.
20. How to solve the service call timeout problem?
When dubbo calls the service unsuccessfully, the default is yes 重试两次
.
21. How does Dubbo solve the security mechanism?
Dubbo uses Tokens to prevent users from bypassing the registry to directly connect, and then manage authorization on the registry. Dubbo also provides service black and white lists to control the callers allowed by the service.
22. The difference between Dubbo and Dubbox?
Dubbox has made some extensions based on dubbo, such as adding services that can be called restful, and updating open source components.
23. The difference between Dubbo and Spring Cloud?
Component | Dubbo | Spring Cloud |
---|---|---|
Service Registry | Zookeeper | Spring Cloud Netfix Eureka / Nacos |
Service call method | RPC | REST API |
Service gateway | no | Spring Cloud Zuul / Spring Cloud Gateway |
breaker | imperfect | Spring Cloud Netfix Hystrix |
Distributed configuration | no | Spring Cloud Config |
Service tracking | no | Spring Cloud Sleuth |
Total message stack | no | Spring Cloud Bus |
data flow | no | Spring Cloud Stream |
Batch task | no | Spring Cloud Task |
The biggest difference: The bottom layer of Dubbo uses a NIO framework such as Netty, which is transmitted based on the TCP protocol, and completes the RPC communication with Hession serialization.
SpringCloud is based on the Http protocol + Rest interface to call the remote process communication. Relatively speaking, Http requests will have larger packets and occupy more bandwidth. However, REST is more flexible than RPC. The dependency of the service provider and the caller only relies on a contract, and there is no strong dependency at the code level.