Dubbo Overview, Architecture, and a Step‑by‑Step Demo with Zookeeper and Spring

This article introduces Dubbo’s background, explains the evolution of e‑commerce architectures to RPC‑based distributed systems, details Dubbo’s components, advantages, and drawbacks, and provides a complete Maven‑based demo—including Zookeeper installation, Spring configuration, and Java code—for building and consuming a Dubbo service.

Java Captain
Java Captain
Java Captain
Dubbo Overview, Architecture, and a Step‑by‑Step Demo with Zookeeper and Spring

Dubbo Background and Overview

Dubbo originated from e‑commerce systems; the article first describes the evolution of such systems from monolithic ORM‑based applications to vertical MVC architectures, then to distributed RPC services, and finally to SOA‑based service‑oriented architectures.

Monolithic Application (ORM) : When traffic is low, a single application hosts all functions to reduce deployment nodes and cost. The drawback is increasing resource consumption and maintenance difficulty as traffic grows.

Vertical Application (MVC) : Separates functions into independent modules, improving scalability and reducing coordination cost, but leads to code duplication across modules.

Distributed Application (RPC) : As vertical modules increase, inter‑module communication becomes inevitable; core business is extracted into independent services, forming a stable service center.

Service‑Oriented Architecture (SOA) : With many services, calls and dependencies become complex, leading to a service‑oriented framework that encapsulates service provision, invocation, connection handling, serialization, discovery, routing, and logging.

The evolution diagram shows the transition from monolithic to SOA architectures.

What is RPC?

Remote Procedure Call (RPC) enables a program on server A to invoke a method on server B over a network, abstracting away the underlying network details. It typically uses TCP or UDP and follows a client‑server model where the client sends a request, the server processes it, and returns a response.

Dubbo Overview

Dubbo is a high‑performance, transparent RPC framework for Java that also provides SOA service governance. It serves thousands of services with billions of daily invocations, primarily used within Alibaba Group and other enterprises.

Dubbo Architecture

Provider : The service provider that exposes services. Consumer : The client that invokes remote services. Registry : The service registration and discovery center. Monitor : Collects call counts and latency for monitoring.

Call Flow :

Service container starts and loads providers.

Providers register themselves with the registry.

Consumers subscribe to required services from the registry.

The registry pushes provider address lists to consumers (via long‑connection if changes occur).

Consumers select a provider using a soft load‑balancing algorithm; if a call fails, another provider is tried.

Consumers and providers aggregate call counts and latency, sending statistics to the monitor every minute.

Dubbo Registry Types

Supported registries include Multicast, Zookeeper, Redis, and Simple.

Dubbo Advantages

Transparent remote method invocation – calls look like local method calls without API intrusion.

Soft load balancing and fault tolerance, usable as a software replacement for hardware load balancers.

Automatic service registration and configuration management via Zookeeper or similar coordination services.

Comprehensive service monitoring and governance through Dubbo‑admin and Dubbo‑monitor.

Dubbo Disadvantages

Only supports the Java language.

Dubbo Demo – Step‑by‑Step

The demo builds a simple Dubbo project using Zookeeper and Spring.

1. Install Zookeeper

Zookeeper acts as the distributed registry. After installation, start zkServer.cmd to launch the Java process.

2. Create Maven Project

Project structure:

dubbo-api : Holds the shared service interface.

dubbo-provider : Implements and exposes the service.

dubbo-consumer : Calls the remote service.

Define the service interface ( DemoService) in dubbo-api:

package com.alibaba.dubbo.demo;
import java.util.List;
public interface DemoService {
    List<String> getPermissions(Long id);
}

Implement the interface in dubbo-provider:

package com.alibaba.dubbo.demo.impl;
import com.alibaba.dubbo.demo.DemoService;
import java.util.ArrayList;
import java.util.List;
public class DemoServiceImpl implements DemoService {
    public List<String> getPermissions(Long id) {
        List<String> demo = new ArrayList<String>();
        demo.add(String.format("Permission_%d", id - 1));
        demo.add(String.format("Permission_%d", id));
        demo.add(String.format("Permission_%d", id + 1));
        return demo;
    }
}

Spring XML for the provider ( provider.xml) registers the application, Zookeeper registry, Dubbo protocol, and the service bean:

<?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://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://code.alibabatech.com/schema/dubbo
                           http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    <!-- Application info -->
    <dubbo:application name="demotest-provider" owner="programmer" organization="dubbox"/>
    <!-- Zookeeper registry -->
    <dubbo:registry address="zookeeper://localhost:2181"/>
    <!-- Dubbo protocol on port 20880 -->
    <dubbo:protocol name="dubbo" port="20880"/>
    <!-- Expose the service -->
    <dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" protocol="dubbo"/>
    <bean id="demoService" class="com.alibaba.dubbo.demo.impl.DemoServiceImpl"/>
</beans>

Provider main class to start the service:

package com.alibaba.dubbo.demo.impl;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.IOException;
public class Provider {
    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("provider.xml");
        System.out.println(context.getDisplayName() + ": here");
        context.start();
        System.out.println("服务已经启动...");
        System.in.read();
    }
}

3. Create Consumer Project

Consumer Spring XML ( consumer.xml) subscribes to the same Zookeeper registry and references the remote service:

<?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://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    <dubbo:application name="demotest-consumer" owner="programmer" organization="dubbox"/>
    <dubbo:registry address="zookeeper://localhost:2181"/>
    <dubbo:reference id="permissionService" interface="com.alibaba.dubbo.demo.DemoService"/>
</beans>

Consumer main class to invoke the remote method:

package com.alibaba.dubbo.consumer;
import com.alibaba.dubbo.demo.DemoService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Consumer {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
        context.start();
        System.out.println("consumer start");
        DemoService demoService = context.getBean(DemoService.class);
        System.out.println(demoService.getPermissions(1L));
    }
}

Run the provider first, then start the consumer; the consumer will print the permission list returned by the provider.

Dubbo Management Console

The console provides routing rules, dynamic configuration, service degradation, access control, weight adjustment, and load balancing.

Download dubbo-admin, replace its configuration into Tomcat’s conf directory, and start Tomcat. After logging in with user root, you can view providers and consumers.

Note that the original Dubbo website is no longer maintained; newer forks such as Dubbox are available.

The complete demo code is hosted on GitHub: https://github.com/nomico271/DatatablesDemo.git

Original article source: blog.csdn.net/noaman_wgs/article/details/70214612

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Distributed SystemsJavaRPCDubbospringZooKeeper
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.