Mastering Dubbo: Core Concepts, Configurations, and Common Pitfalls
This article explains what Dubbo is, its key features such as transparent RPC, cluster fault tolerance, communication protocols, registration centers, serialization options, configuration details, load‑balancing strategies, security mechanisms, common issues and solutions, and compares it with Dubbox and other distributed frameworks.
What is Dubbo
Dubbo is a distributed framework for remote service invocation. Its core includes cluster fault tolerance (transparent RPC, multi‑protocol support, soft load balancing, failover, address routing, dynamic configuration), remote communication (NIO‑based long connections, various thread models, serialization, request‑response), and automatic discovery via a registry.
What can Dubbo do
It provides transparent remote method calls that feel like local calls, requiring only simple configuration and no API intrusion. Soft load balancing and fault‑tolerance can replace hardware load balancers, reducing cost and single points of failure. Services are automatically registered and discovered, eliminating hard‑coded addresses and allowing smooth scaling.
Default communication framework and alternatives
By default Dubbo uses Netty; Mina is also available.
Is service invocation blocking?
By default calls are blocking, but asynchronous calls are possible for methods without return values.
Common registry choices
ZooKeeper is the recommended registry. Alternatives include Multicast, Redis, and Simple registries. ZooKeeper maintains nodes in a tree‑like structure, each identified by a path and storing metadata such as data, data length, creation time, and modification time.
Default serialization framework and alternatives
Hessian is the default serialization; other options are Dubbo’s own serializer, FastJSON, and Java’s built‑in serialization. Hessian uses a binary format, making it lighter and faster than traditional SOAP web services.
Hessian protocol basics:
Client‑server interaction uses HTTP POST.
Auxiliary information (e.g., token) is placed in HTTP headers for security checks or meta‑data.
Method name and parameters are sent as a byte stream in the request body.
Server responses are returned as a byte stream in the HTTP response.
The protocol defines how the client serializes the request and how the server deserializes it back into objects, executes the method, and serializes the result.
Service provider failure eviction principle
Failure eviction is based on ZooKeeper’s temporary node mechanism.
Versioning without affecting old services
Use multi‑version development by adding a version attribute in the configuration to distinguish versions.
Solving long service call chains
Integrate Zipkin for distributed service tracing.
Core configuration items
dubbo:service/
dubbo:reference/
dubbo:protocol/
dubbo:registry/
dubbo:application/
dubbo:provider/
dubbo:consumer/
dubbo:method/
Recommended Dubbo protocol
The default protocol is the Dubbo protocol.
Direct connection to a specific service when multiple registrations exist
Yes, you can connect directly by adjusting the configuration or using telnet.
Security mechanisms
Dubbo uses token authentication to prevent bypassing the registry, manages authorizations in the registry, and provides black‑list/white‑list controls for allowed callers.
Cluster fault‑tolerance strategies
Read operations should use Failover (automatic retry, default two retries). Write operations should use Failfast (immediate failure on first error).
Common problems and solutions
1. XML and properties both configured; properties ineffective
Properties take effect only when XML configuration is absent.
2. Dubbo checks dependencies at startup and throws exceptions
Set check to false during testing if some services are intentionally unavailable or have circular dependencies.
3. Development service registration affecting consumers
Configure the provider’s register attribute to false so that only consumers subscribe without registering the developing service.
4. Spring 2.x initialization deadlock
Avoid calling applicationContext.getBean() inside service implementations, or set the provider’s deplay attribute to -1 to delay exposure until Spring initialization completes.
5. Service not registering
Check that Dubbo JARs are on the classpath, there are no duplicate JARs, the Spring configuration for exposing services is loaded, and network connectivity to the registry is functional.
6. RpcException: No provider available for remote service
Verify the registry address, confirm the provider appears in the registry, and ensure the provider is running.
7. Message sending failure
Ensure that method parameters and return types implement Serializable.
Difference between Dubbo and Dubbox
Dubbox is an extension of Dubbo created by Dangdang, adding features such as RESTful service calls and updated open‑source components.
Other distributed frameworks
Examples include Spring Cloud, Facebook’s Thrift, and Twitter’s Finagle.
Supported protocols and their scenarios
dubbo : single long connection, NIO async, suitable for high concurrency, small payloads, many consumers per provider; TCP transport, asynchronous, Hessian serialization.
rmi : JDK standard RMI, requires Serializable, uses blocking short connections, mixed packet sizes, suitable for balanced consumer/provider counts, can transfer files; TCP transport.
webservice : CXF‑based, interoperable with native WebService; short HTTP connections, synchronous, good for system integration and cross‑language calls.
http : Spring’s HttpInvoke, short HTTP connections, suitable when providers outnumber consumers and browser/JS calls are needed.
hessian : HTTP‑based, Jetty embedded, synchronous, large input parameters, provider‑heavy workloads, can transfer files.
memcache and redis : RPC over respective in‑memory stores.
Dubbo cluster load‑balancing strategies
Random: randomly selects a provider, useful for dynamic weight adjustments.
RoundRobin: evenly distributes requests but may cause request accumulation.
LeastActive: prefers providers with fewest active calls, avoiding slow providers.
ConsistentHash: routes identical parameters to the same provider; supports virtual nodes for failover.
Service call timeout handling
Dubbo retries twice by default, which can cause duplicate operations (e.g., multiple emails). To address timeout issues, disable the retry mechanism for critical services, set appropriate timeout values, and keep business logic on the server side while the client performs only validation and invocation.
Dubbo’s retry mechanism also provides QoS by routing timed‑out requests to other machines, but it should be tuned based on real‑world traffic patterns.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
