Home Java javaTutorial What 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 style="font-size:12px;">public interface IService extends Remote {

    public String queryName(String no) throws RemoteException;

}</span>
Copy after login

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());
    }
    
}
Copy after login

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) {
            
        }
    }
}
Copy after login

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) {
            
        }
    }
}
Copy after login

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 of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The handwritten RPC framework is really not just for pretending to be 13! The handwritten RPC framework is really not just for pretending to be 13! Aug 16, 2023 pm 05:01 PM

You may not have been asked, maybe you're lucky, or maybe you're not at this level yet. Usually the monthly salary is more than 20k, and they will basically ask some design questions. From the interviewer's perspective: Asking this type of question is better than writing an eight-part essay, which involves many technical points. For example: knowledge about design patterns, communication protocols, dynamic agents, virtualization, thread pools, etc.

Alibaba interviewer: Please handwrite an RPC framework for me. Alibaba interviewer: Please handwrite an RPC framework for me. Aug 17, 2023 pm 04:24 PM

RPC is a computer communication protocol. This protocol allows a program running on one computer to call a subroutine on another computer without the developer having to additionally program this interaction.

Principles and applications of RPC framework in Go language Principles and applications of RPC framework in Go language Jun 01, 2023 pm 03:01 PM

1. The concept of RPC framework In distributed systems, data often needs to be transferred between different servers and clients. The RPC (RemoteProcedureCall) framework is a commonly used technical means. The RPC framework allows applications to call functions or methods of another execution environment through remote messaging, thereby enabling the program to run on different computers. There are currently many RPC frameworks on the market, such as Google's gRPC, Thrift, Hessian, etc. This article mainly introduces

How to develop RPC framework in PHP? How to develop RPC framework in PHP? May 13, 2023 pm 03:22 PM

RPC (RemoteProcedureCall) is an inter-process communication protocol that allows different processes to communicate and collaborate over the network on different physical machines. The RPC framework is attracting more and more attention because it can help developers easily implement the development of distributed systems. In this article, we will introduce step by step how to use PHP to develop RPC framework. 1. What is the RPC framework? The RPC framework is a framework used to implement remote procedure calls. In RPC-based

What rpc frameworks are there? What rpc frameworks are there? Aug 03, 2023 am 10:17 AM

The rpc frameworks include: 1. gRPC, a high-performance, open-source RPC framework developed by Google; 2. Apache Thrift, a cross-language RPC framework developed and open-sourced by Facebook; 3. Apache Dubbo, a high-performance, lightweight RPC framework, suitable for large-scale distributed systems; 4. Apache Axis2, an RPC framework based on Web service standards; 5. Spring Cloud, an open source framework for building distributed systems.

Go language RPC framework evaluation: performance, ease of use, community support comparison Go language RPC framework evaluation: performance, ease of use, community support comparison Feb 27, 2024 pm 09:12 PM

As an important modern programming language, Go language is increasingly used in distributed system development. When building a distributed system, the choice of RPC (remote procedure call) framework is often crucial. This article will conduct a horizontal evaluation of the current mainstream Go language RPC frameworks, compare their advantages and disadvantages in terms of performance, ease of use, and community support, and attach specific code examples. 1. Performance comparison In distributed systems, performance is often one of the primary indicators that developers pay attention to. The following are some main

How to implement a high-concurrency RPC framework in go language How to implement a high-concurrency RPC framework in go language Aug 05, 2023 pm 12:49 PM

Introduction to how to implement high-concurrency RPC framework in Go language: With the rapid development of the Internet, high-concurrency applications have attracted more and more attention. Using the RPC (RemoteProcedureCall) framework is a common solution. This article will introduce how to implement a high-concurrency RPC framework in the Go language, and will come with code examples. Introduction to the RPC framework: RPC is a communication protocol that allows a computer program to call a subroutine in another address space (usually located on the remote computer) without

What are the RPC frameworks in PHP7.0? What are the RPC frameworks in PHP7.0? May 29, 2023 am 11:10 AM

With the continuous development of computer technology, distributed systems have become mainstream, and remote procedure call (RPC) is an important means to implement distributed systems. As a popular Web programming language, PHP also has its own RPC framework, among which some new RPC frameworks were introduced in PHP7.0 version. This article will introduce the common RPC frameworks and their characteristics in PHP7.0. PHPRemoteProcedureCall(phpRPC)phpRPC is a lightweight RP

See all articles