Dubbo Service Invocation Mechanism Explained

Basic Architecture and Interaction Principle

In the Dubbo distributed service framework, all service invocations are based on Java interfaces. This interface contract design ensures decoupling between service providers and consumers. The specific workflow is as follows:

  1. Interface Agreement: Service provider and consumer first need to jointly define a set of standard service interfaces
  2. Service Registration: After provider implements these interfaces, register the service instance to the registry
  3. Service Discovery: Consumer obtains available service list from registry
  4. Remote Invocation: Consumer initiates RPC call to provider through dynamic proxy

Maven Project Structure Explanation

Dubbo projects typically use a multi-module Maven project structure with typical layout as follows:

dubbo-demo/
├── dubbo-api/         # Interface definition module
├── dubbo-provider/    # Service provider
└── dubbo-consumer/    # Service consumer

Parent Project

Create a parent project to manage all modules, remove the src directory.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>icu.wzk</groupId>
        <artifactId>dubbo-test</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>pom</packaging>
        <modules>
            <module>wzk-service-api</module>
            <module>wzk-producer</module>
            <module>wzk-consumer</module>
        </modules>

        <properties>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <dubbo.version>2.7.5</dubbo.version>
        </properties>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.apache.dubbo</groupId>
                    <artifactId>dubbo</artifactId>
                    <version>${dubbo.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.dubbo</groupId>
                    <artifactId>dubbo-registry-zookeeper</artifactId>
                    <version>${dubbo.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.dubbo</groupId>
                    <artifactId>dubbo-rpc-dubbo</artifactId>
                    <version>${dubbo.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.dubbo</groupId>
                    <artifactId>dubbo-remoting-netty4</artifactId>
                    <version>${dubbo.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.dubbo</groupId>
                    <artifactId>dubbo-serialization-hessian2</artifactId>
                    <version>${dubbo.version}</version>
                </dependency>
            </dependencies>
        </dependencyManagement>

</project>

API Module

This module is used to define interface abstract classes and does not provide actual implementation.

Interface Definition

package icu.wzk.service;

public interface WzkHelloService {
    String sayHello(String name);
}