InfoQ Software Architects' Newsletter

A monthly overview of things you need to know as an architect or aspiring architect.

View an example

QCon San Francisco (Nov 18-22): Get assurance you’re adopting the right software practices. Register Now

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/ )

  • Container is responsible for launching, loading, and running the service Provider
  • Provider registers its services to Register during its initialization
  • Consumer subscribes the services it needs from the Register when it starts
  • Register returns the Provider s list to Consumer , and when a change occurs, the Register push the changed data to Consumer
  • Based on a soft load balancing algorithm, the Consumer will select one of the Provider s and executes the invocation, automatically choose another Provider when a fail occurs.
  • 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.

    The InfoQ Newsletter

    A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example The InfoQ Newsletter

    A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example

  • Get a quick overview of content published on a variety of innovator and early adopter technologies
  • Learn what you don’t know that you don’t know
  • Stay up to date with the latest information from the topics you are interested in
  • InfoQ Dev Summit Munich
    September 26-27, 2024

    InfoQ Dev Summit Munich is a two-day software conference featuring 22 technical talks sharing actionable insights on Generative AI, security, modern web apps, and more.
    Learn from senior developers facing the same challenges as you as they share proven tactics, not just trends, empowering you to make smart, focused choices for your immediate dev roadmap.
    Register Now