BT

InfoQ Homepage News Apache Dubbo, a Java-Based RPC Framework, Graduates to Top-Level Project

Apache Dubbo, a Java-Based RPC Framework, Graduates to Top-Level Project

This item in japanese

Bookmarks

The Apache Software Foundation recently announced Apache Dubbo as a top-level project. Apache Dubbo is an open source, remote procedure call framework based on Java. It was originally developed at Alibaba, open-sourced in 2011, and entered the Apache Incubator in February 2018. Dubbo brings key functionalities such as interface-based remote call, fault tolerance and load balancing, and automatic service registration and discovery.

The Dubbo architecture is shown below:

(Image taken from https://dubbo.apache.org/)

  1. Container is responsible for launching, loading, and running the service Provider
  2. Provider registers its services to Register during its initialization
  3. Consumer subscribes the services it needs from the Register when it starts
  4. Register returns the Providers list to Consumer, and when a change occurs, the Register push the changed data to Consumer
  5. Based on a soft load balancing algorithm, the Consumer will select one of the Providers and executes the invocation, automatically choose another Provider when a fail occurs.
  6. Both Consumer and Provider will count the number service invocations and time-consuming in memory, and send the statistics to Monitor every minute.

Apache Dubbo features include:

  • A transparent interface based RPC
  • Intelligent load balancing, which supports multiple load balancing strategies out of the box
  • Automatic service registration and discovery
  • High extensibility, micro-kernel and plugin design which ensures that it can easily be extended by third party implementation across core features like protocol, transport, and serialization
  • Runtime traffic routing, which can be configured at runtime so that traffic can be routed according to different rules, making it easy to support features such as blue-green deployment, data center aware routing, etc
  • Visualized service governance, which provides rich tools for service governance and maintenance such as querying service metadata, health status, and statistics

To get started using Dubbo, developers first add the Maven dependency:

<dependencies>
    <dependency>
        <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.7.2<</version>
    </dependency>
    <dependency>
        <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo-dependencies-zookeeper</artifactId>
        <version>2.7.2<</version>
        <type>pom</type>
    </dependency>
</dependencies>

Next, a service interface is defined and implemented in the provider:

package org.apache.dubbo.samples.api;

//service interface
public interface GreetingService {
    String sayHello(String name);
}
 
//provider, implementation of service interface
public class GreetingServiceImpl implements GreetingService {
    @Override
    public String sayHello(String name) {
        return "Hello " + name;
    }
}

The provider would be configured as follows:

package org.apache.dubbo.demo.provider;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.samples.api.GreetingService;
import java.io.IOException;
 
public class Application {

    public static void main(String[] args) throws IOException {
        ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.setApplication(new ApplicationConfig("first-dubbo-provider"));
        serviceConfig.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
        serviceConfig.setInterface(GreetingService.class);
        serviceConfig.setRef(new GreetingServiceImpl());
        serviceConfig.export();
        System.in.read();
    }
}

And then built and run:

# mvn clean package
# mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=org.apache.dubbo.demo.provider.Application exec:java

The following code snippets show how to create a consumer:

package org.apache.dubbo.demo.consumer;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.samples.api.GreetingService;

public class Application {
    public static void main(String[] args) {
        ReferenceConfig referenceConfig = new ReferenceConfig();
        referenceConfig.setApplication(new ApplicationConfig("first-dubbo-consumer"));
        referenceConfig.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
        referenceConfig.setInterface(GreetingService.class);
        GreetingService greetingService = referenceConfig.get();
        System.out.println(greetingService.sayHello("world"));
    }
}

Beginning a new project using Apache Dubbo is relatively simple; developers can follow the steps above, or by use Dubbo's Spring initializr, which is basically a fork of Spring initializr. In addition to Java, Dubbo supports Node.js, Python, and PHP.

Apache Dubbo is in use at companies such as Alibaba Group, China Life, China Telecom, Dangdang, Didi Chuxing, Haier, Industrial and Commercial Bank of China, NetEase, Qunar, and Youzan.

More details about Dubbo can be found at https://dubbo.apache.org. Developers who want to contribute should access the contributor guide. There is also extensive documentation available.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Java RPC from China

    by Greg Liebowitz /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Great for remote code execution exploits. Probably a good idea to block this one on your Nexus/Artifactory firewall.

  • Re: Java RPC from China

    by Richard Richter /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Funny, something like this ("RPC from China?") crossed my mind too, but it's open-sourced. Is something in the code base that hints at some real problem?
    On the other side, while I like RPC simplicity, I'd like to see benefits mentioned in the article. How faster compared to Java's RPC, how faster compared to REST or SOAP or protobuf.
    I randomly checked Consul support for registry and related issue on GitHub was littered with Chinese, so that may be one problem (I hope the source code is in English :-)).

  • Is there a feedback loop from Monitor to Registry or Consumer

    by Richard Clayton /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    In terms of implementation, what's the purpose of Monitor outside of keeping metrics? It's my understanding that Google's internal RPC framework will keep statistics for the purpose of routing and load shedding. Is that the intent of Monitor?

  • Re: Is there a feedback loop from Monitor to Registry or Consumer

    by Diogo Carleto /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hi Richard, I’m not sure but I think it’s only for metrics. Take a look in the monitor extension dubbo.apache.org/en-us/docs/dev/impls/monitor.html

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.