Mastering Dubbo: From Java RMI Basics to Building a Full RPC Application
This article explains the fundamentals of remote method invocation, compares traditional RMI with modern RPC frameworks, introduces Dubbo's architecture and roles, and provides a step‑by‑step guide to quickly develop, build, and run a complete Dubbo application using API‑centric configuration and multicast registration.
In distributed systems, remote invocation is a fundamental building block. Historically, technologies such as CORBA, RMI, EJB, and WebService have been used, and today lightweight frameworks like gRPC, Finagle, and Dubbo dominate service‑oriented architectures.
Java RMI Overview
Java RMI (Remote Method Invocation) allows a client to invoke methods on a remote Java object as if it were a local call, providing an object‑oriented alternative to traditional RPC.
Java RMI Working Principle
Server registers the service and binds its address.
Client obtains the target address from the RMI registry.
Client calls a local Stub object, which looks like a local method call.
The Stub packages the invocation and sends it over the network.
The server-side Skeleton receives the request and unpacks it.
The Skeleton invokes the actual service object and returns the result.
Java RMI Basic Concepts
Remote calls are defined through Java interfaces .
Client uses a Stub and server uses a Skeleton to disguise remote calls as local.
RMI provides its own registry for service registration and discovery.
Before J2SE 1.5, developers needed to pre‑compile Stub and Skeleton classes with rmic; later versions generate them dynamically.
Dubbo Basic Concepts
Dubbo follows the same interface‑based contract model as RMI, using a registry for service registration and discovery, and proxy classes to hide communication details. The four main roles are:
Service Provider – exposes services and registers them.
Service Consumer – subscribes to services to obtain provider addresses.
Registry – stores provider addresses and pushes updates to consumers.
Monitoring Center – collects runtime metrics such as call count and latency.
Runtime Container – manages the lifecycle of providers.
During deployment, providers expose services on a port and register them; consumers subscribe to the registry to receive address lists. At runtime, consumers select a provider from the list, invoke the service, and both sides report status to the monitoring center.
API‑Based Dubbo Application
Dubbo applications are typically assembled with Spring. To simplify the example, the tutorial uses the Dubbo API directly, avoiding complex XML or Spring Boot configuration, and employs multicast ( multicast://224.5.6.7:1234) as the registry.
Key steps to implement the provider:
Create a ServiceConfig with the service interface type.
Instantiate an ApplicationConfig and attach it to the service config.
Create a RegistryConfig using the multicast address and attach it.
Set the service interface and its implementation in the service config.
Expose the service (default port 20880) and keep the process alive.
Key steps to implement the consumer:
Create a ReferenceConfig with the service interface type.
Instantiate an ApplicationConfig and attach it.
Create a matching RegistryConfig (same multicast address).
Set the service interface in the reference config.
Obtain the proxy from the reference config and invoke sayHi("dubbo"), which returns hi, dubbo.
Quickly Generate Dubbo Application
Dubbo provides a public service at start.dubbo.io to generate a Spring Boot‑based Dubbo project. Users specify Maven groupId, artifactId, service name, version, role (provider or consumer), and optional embedded Zookeeper or QoS settings, then download the generated project.
After cloning the generated repository, run mvn clean package to build, then start the provider with the appropriate Maven command. When the provider logs “first‑dubbo‑provider is running”, the client can be started similarly, and the result hi, dubbo will be printed.
The generated Spring Boot application includes an embedded ZooKeeper (port 2181) and can be managed via QoS commands (e.g., ls, online, offline) through telnet.
Conclusion
The article starts from Java RMI to introduce the core concepts of distributed remote calls, then uses a simple multicast registry and API‑centric programming to demonstrate a complete Dubbo application. Understanding ServiceConfig and ReferenceConfig prepares developers for more advanced Spring XML or Spring Boot configurations, while the start.dubbo.io service and QoS tools simplify rapid development and basic operations.
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.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
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.
