I met Dubbo

Why does Dubbo say he has high performance?

High performance starts with the underlying principles. Since it is an RPC framework that mainly does remote procedure (method) calls, improving performance starts from the two most critical and time-consuming aspects: serialization and network communication.

  • Serialization: When we learned about Java network development, we learned that in order for native objects to be transferred over the network, we must implement the Serializable interface, which must be serialized. We serialize in many ways: XML, JSON, binary streams… The most efficient of these are binary streams (because computers are binary). Dubbo, however, uses the most efficient binary.

  • Network communication: Different from HTTP, which requires seven steps (three handshakes and four waves), Dubbo uses Socket communication mechanism to improve communication efficiency in one step. In addition, it can establish long connections without repeated connections and directly transfer data

Other RPC frameworks

gRPC

Thrift

HSF

.

Dubbo’s past lives

Dubbo has been used as a framework within Alibaba.

In 2011, Dubbo was hosted on GitHub (open source)

The update was discontinued after version 2.4.11 was released in November 2014. Since then, many companies have opened source their own Dubbo based variants (such as Dubbo X of Dangdang and Dubbo K of Kaola.com).

In January 2018, Alibaba and Dangdang.com combined Dubbo and Dubbo X and released version 2.6. On New Year’s Eve of 2018, Ali contributed Dubbo to Dubbo The Apache foundation

Apache maintains and updates Dubbo since New Year’s Eve 2018

Dubbo overview

Apache Dubbo (incubating) | ˈ d ʌ b goes ʊ | is a high-performance, lightweight open source Java RPC framework, it provides three main core competencies: an interface of remote method invocation (rmi), intelligent fault tolerance and load balancing, and automatic registration and discovery of services.

Dubbo is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation solutions and service governance solutions.

Video explanation is coming!! Can be directly click to watch

This video is produced by Power Node and covers:

  • From the beginning of the basic step-by-step detailed explanation of the concept of RPC, PRC in the distributed application of the important role.
  • Dubbo distributed services framework application basics.
  • Traditional applications to distributed and microservices shift thinking.
  • Characteristics of the Dubbo protocol.
  • Detailed development process of Dubbo distributed service, implementation and deployment of Dubbo service, service management of Zookeeper, etc.

Watch online: www.bilibili.com/video/BV1Sk.

Data download: www.bjpowernode.com/javavideo/1…

Liverpoolfc.tv: dubbo.apache.org/zh-cn/

Features:

Interface oriented proxy: call the method of the interface, call the method of the SERVER B in A, dubbo to implement the call to B, no need to care about the details of implementation, just like MyBatis to access Dao’s interface, can operate the database. Don’t worry about the implementation of Dao interface methods. This development is convenient and comfortable.

Basic architecture

  • Provider: A service Provider that exposes a service. At startup, the service Provider registers its services with the registry.
  • Service Consumer: the service Consumer who invokes the remote service. When the service Consumer starts up, it subscribes to the registry for the service it needs. The service Consumer selects one provider from the provider address list and invokes it based on the soft load balancing algorithm.
  • Registry: The Registry returns a list of service provider addresses to the consumer. If there are changes, the Registry pushes the change data to the consumer based on the long connection
  • Monitor: Service consumers and providers accumulate call times and call time in memory and regularly send statistics to the monitoring center once a minute

Call relationship description:

  • The service container is responsible for starting, loading, and running the service provider.
  • At startup, service providers register their services with the registry.
  • At startup, service consumers subscribe to the registry for the services they need.
  • The registry returns a list of service provider addresses to the consumer, and if there are changes, the registry pushes the change data to the consumer based on the long connection.
  • The service consumer, from the provider address list, selects one provider to call based on the soft load balancing algorithm. If the call fails, selects another one to call.
  • Service consumers and providers accumulate calls and call times in memory and regularly send statistics to the monitoring center every minute.

Dubbo supports the protocol

Supports multiple protocols: Dubbo, Hessian, RMI, HTTP, WebService, Thrift, memcached, redis. Dubbo officially recommends using the Dubbo protocol. The default dubbo port is 20880

Using the Dubbo protocol, spring configuration files are added to:

<dubbo:protocol name="dubbo" port="20880" />

E-commerce platform demand

An e-commerce platform system demand, users browse goods; Select goods to place an order, the order system needs to obtain the delivery address in the user information; Request payment completion from the payment system.

Direct connection mode dubbo

Point-to-point direct connection projects: the consumer accesses the service provider directly, without a registry. The consumer must specify the service provider’s access address (URL).

A consumer accesses a fixed service provider directly through a URL address. This URL is going to be the same.

Achieve the goal

Users visit ——> [product website services] visit —–> [Order Services]

implementation

In the case of JavaSE, service providers and service consumers are JavaSE projects

(1) Create a service provider: order service

A. Create A Java Project

Project Name:

link-orderservice-provider

Set version to 1.0.0

B, maven pom. XML

Add the JDK1.8 build plug-in to the < plugins> TAB under < build>

C, create Order entity class: Order

D. New OrderService interface: OrderService

E. Create an implementation class for the interface: OrderServiceImpl

F. Create a Dubbo configuration file

orderservce-provider.xml

G. Test the configuration file

H. Install the local JAR into maven repository

For the methods in the service interface to be used by the consumer, the consumer project needs to know the interface name and the method names, parameters, and so on in the interface. These information service providers know. You need to package the interface’s class file as a JAR.

The service interface project’s class files are packaged as Jars and installed into the Maven repository, where the provider jars can be used by consumers.

Install is executed using the Maven window of IDEA

(2) Create a service consumer: product website

I. Create a Java Project

Project name: link-main-web

J, maven pom XML

Add the JDK1.8 build plug-in to the < plugins> TAB under < build>

K. Create an interface for purchasing goods

Create an implementation class for the purchase interface

M. Create a Dubbo configuration file

shop-consume.xml

N, executive consumers

Dubbo servitization best practices

The subcontract

You are advised to store service interfaces, service models, and service exceptions in a common package.

Particle size

Service interfaces should be as large-grained as possible. Each service method should represent a function rather than a step of a function. Service interfaces should be divided by service scenarios and abstracted from similar services to prevent interface explosion.

It is not recommended to use abstract general interfaces, such as Map Query (Map). Such interfaces do not have clear semantics and may cause inconvenience in future maintenance.

version

For example, <dubbo:service interface=”com.xxx.XxxService” version=”1.0″ />