Master Apache Dubbo: From Basics to Real‑World RPC Implementation
This article introduces Apache Dubbo, compares it with Eureka, and provides a complete step‑by‑step example—including service interface, implementation, provider and consumer configurations, XML files, and code snippets—plus instructions for installing and using Dubbo‑Admin for monitoring micro‑service deployments.
What is Dubbo?
Apache Dubbo is a high‑performance micro‑service framework that provides RPC communication, traffic governance, and observability, with SDKs for Java, Go, and other languages.
Features: RPC framework, service registry, native cloud support (Dubbo 3.0).
Main versions: 2.7.x and 3.0. Official SDKs for Java and Go.
Adopted by: Alibaba, Ele.me, DingTalk, ICBC, Xiaomi, etc.
Dubbo vs. Eureka
Dubbo uses Zookeeper as its registry, follows CP consistency, supports built‑in fault tolerance and load balancing, and implements its own Netty‑based protocol. Eureka relies on HTTP, follows AP consistency, and provides fault tolerance and load balancing via Hystrix and Ribbon.
Overall, Dubbo is a packaged micro‑service middleware with a custom RPC protocol that can offer better performance than HTTP‑based solutions.
Dubbo Usage Example
The following example demonstrates a simple RPC interaction using Dubbo with Zookeeper as the registry.
Roles
Zookeeper – service registry managing the service list.
Provider – publishes the service.
Consumer – calls the remote service as if it were a local method.
Provider
Define service interface
<code>public interface OrderService {
String createOrder(String request);
}</code>Implement the service
<code>public class OrderServiceImpl implements OrderService {
@Override
public String createOrder(String request) {
return "create order success, request : " + request;
}
}</code>Start the provider application
<code>public class RpcDubboProviderApp {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("classpath:dubbo.xml");
context.start();
System.in.read(); // press any key to exit
}
}</code>Configuration (dubbo.xml)
<code><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<!-- Provider application -->
<dubbo:application name="rpc-dubbo-provider"/>
<!-- Zookeeper registry -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- Dubbo protocol on port 20880 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- Expose the service -->
<dubbo:service interface="io.zhengsh.rpc.api.OrderService" ref="orderService"/>
<!-- Service implementation bean -->
<bean id="orderService" class="io.zhengsh.rpc.provider.OrderServiceImpl"/>
</beans>
</code>Consumer
Consumer configuration (dubbo.xml)
<code><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="rpc-dubbo-consumer"/>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:protocol name="dubbo" port="20890"/>
<dubbo:reference id="orderService"
interface="io.zhengsh.rpc.api.OrderService"/>
</beans>
</code>Consumer code
<code>public class RpcDubboConsumerApp {
public static void main(String[] args) {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("classpath:dubbo.xml");
context.start();
OrderService demoService = (OrderService) context.getBean("orderService");
String hello = demoService.createOrder("iPhone 19");
System.out.println(hello);
}
}</code>Run the provider first, then the consumer; the console should display the success message.
Dubbo Monitoring with Dubbo‑Admin
Install Dubbo‑Admin by cloning the repository, configuring the registry address in
application.properties, building with Maven, and starting the server. Access the UI at
http://localhost:8080(default credentials root/root) to view registered services, test calls, and monitor health.
Reference documentation:
https://dubbo.apache.org/zh/docsv2.7/user/quick-start/
https://github.com/apache/dubbo-admin/blob/develop/README_ZH.md
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
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.