search
HomeJavajavaTutorialWhat are the rpc frameworks?

What are the rpc frameworks?

Oct 29, 2020 pm 03:04 PM
rpc framework

rpc frameworks include: 1. RMI, remote method invocation; 2. Hessian, remote method invocation based on HTTP; 3. Dubbo, Taobao's open source TCP-based RPC framework.

What are the rpc frameworks?

rpc framework has:

RPC is the abbreviation of remote procedure call , widely used in large-scale distributed applications, its role is to facilitate the vertical split of the system and make the system easier to expand. There are many RPC frameworks in Java, each with its own characteristics. The widely used ones include RMI, Hessian, Dubbo, etc. Another feature of RPC is that it can cross languages. This article only takes RPC in the JAVA language as an example.

There is a logical relationship diagram for RPC, taking RMI as an example:


##Other framework structures are similar. The difference lies in the serialization method of objects, the communication protocol for transmitting objects, and the management and failover design of the registration center (using zookeeper).

The client and server can run in different JVMs. The client only needs to introduce the interface. The implementation of the interface and the data required for runtime are all on the server side. RPC mainly relies on technology. It is a serialization, deserialization and transmission protocol. In JAVA, it corresponds to the serialization, deserialization and transmission of serialized data. RMI's serialization and deserialization are native to JAVA. Serialization and deserialization in Hessian are private, and the transmission protocol is HTTP. Dubbo's serialization can be selected from a variety of options. Hessian's serialization protocol is generally used. The transmission is TCP protocol, using the high-performance NIO framework Netty. I also know something about serialization, such as Google's ProBuffer, JBoss Marshalling and Apache Thrift, etc. I have previously written a blog post introducing ProBuffer

1. RMI (Remote Method Invocation)

JAVA’s own remote method invocation tool, but it has certain limitations. After all, it is the original design of the JAVA language. Later, the principles of many frameworks were based on RMI. The use of RMI is as follows:

External interface

<span>public interface IService extends Remote {

    public String queryName(String no) throws RemoteException;

}</span>

Service implementation

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

// 服务实现
public class ServiceImpl extends UnicastRemoteObject implements IService {

    /**
     */
    private static final long serialVersionUID = 682805210518738166L;

    /**
     * @throws RemoteException
     */
    protected ServiceImpl() throws RemoteException {
        super();
    }

    /* (non-Javadoc)
     *
     */
    @Override
    public String queryName(String no) throws RemoteException {
        // 方法的具体实现
        System.out.println("hello" + no);
        return String.valueOf(System.currentTimeMillis());
    }
    
}

RMI client

import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

// RMI客户端
public class Client {

    public static void main(String[] args) {
        // 注册管理器
        Registry registry = null;
        try {
            // 获取服务注册管理器
            registry = LocateRegistry.getRegistry("127.0.0.1",8088);
            // 列出所有注册的服务
            String[] list = registry.list();
            for(String s : list){
                System.out.println(s);
            }
        } catch (RemoteException e) {
            
        }
        try {
            // 根据命名获取服务
            IService server = (IService) registry.lookup("vince");
            // 调用远程方法
            String result = server.queryName("ha ha ha ha");
            // 输出调用结果
            System.out.println("result from remote : " + result);
        } catch (AccessException e) {
            
        } catch (RemoteException e) {
            
        } catch (NotBoundException e) {
            
        }
    }
}

RMI server

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

// RMI服务端
public class Server {

    public static void main(String[] args) {
        // 注册管理器
        Registry registry = null;
        try {
            // 创建一个服务注册管理器
            registry = LocateRegistry.createRegistry(8088);

        } catch (RemoteException e) {
            
        }
        try {
            // 创建一个服务
            ServiceImpl server = new ServiceImpl();
            // 将服务绑定命名
            registry.rebind("vince", server);
            
            System.out.println("bind server");
        } catch (RemoteException e) {
            
        }
    }
}

Service registration management The server is written in the Server, and of course it can be extracted as a separate service. In some other frameworks, Zookeeper is often used to play the role of registration management.

2. Hessian (HTTP-based remote method invocation)

Based on HTTP protocol transmission, its performance is still good It's not perfect. Load balancing and failover depend on the application's load balancer. The use of Hessian is similar to RMI. The difference is that the role of Registry is downplayed. It is called through the displayed address and uses HessianProxyFactory to create a proxy object based on the configured address. In addition Also introduce the Hessian Jar package.


3. Dubbo (Taobao open source TCP-based RPC framework)

The high-performance RPC framework based on Netty is open sourced by Alibaba. The overall principle is as follows:


##Before understanding Dubbo, you must first have a deep understanding of Zookeeper. Once you understand zookeeper, Dubbo will have no secrets.

The detailed description of Dubbo is very detailed in Taobao Open Source. Dubbo is used in many production projects at work, and many things that need attention are also discovered in the process, especially that Numerous configurations and improper settings will be annoying. It is best to customize and optimize it based on the existing open source Dubbo.

Related free learning recommendations:
java basic tutorial

The above is the detailed content of What are the rpc frameworks?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to elegantly obtain entity class variable names to build database query conditions?How to elegantly obtain entity class variable names to build database query conditions?Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list?How to use the Redis cache solution to efficiently realize the requirements of product ranking list?Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

How to safely convert Java objects to arrays?How to safely convert Java objects to arrays?Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How do I convert names to numbers to implement sorting and maintain consistency in groups?How do I convert names to numbers to implement sorting and maintain consistency in groups?Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the default run configuration list of SpringBoot projects in Idea for team members to share?How to set the default run configuration list of SpringBoot projects in Idea for team members to share?Apr 19, 2025 pm 11:24 PM

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment