preface

In the interview, the representative work of the RPC framework Dubbo has been hot, and the interviewer will ask questions from various angles based on experience, and like peeling an onion layer by layer into the underlying principles, so simply looking at the conventional interview questions is far from enough, it is best to read the source code. On the other hand, the program ape in the usual work and little contact with the source code, and their hard gnaw source code is also difficult.

Java Oop, Java Collections containers, Java exceptions, concurrent programming, Java reflection, Java serialization, JVM, Redis, Spring MVC, MyBatis, MySQL database, messaging middleware MQ, Dubbo, Linux, ZooKeeper, distributed & data structure and algorithm, etc. 25 thematic technical points, are all small editor in each big factory summary of the interview real questions, there have been many fans with this PDF to win many big factory offer. Today, here is a summary to share to everyone! [Finished]

The full version of the Java interview questions address: 2021 latest interview questions collection collection.

The serial number project content link
1 The middleware Java Middleware (2021) Juejin. Cn/post / 694870…
2 Micro service Java Microservices (2021) Juejin. Cn/post / 694906…
3 Concurrent programming Concurrent Programming in Java (2021 latest Edition) Juejin. Cn/post / 695053…
4 Java based Java Basics (2021) Juejin. Cn/post / 695062…
5 Spring Boot Spring Boot Interview Questions (2021 Latest edition) Juejin. Cn/post / 695137…
6 Redis Redis Interview Questions (2021 Latest edition) Juejin. Cn/post / 695166…
7 Spring MVC Spring MVC (2021) Juejin. Cn/post / 695166…
8 Spring Cloud Spring Cloud Interview Questions (2021) Juejin. Cn/post / 695245…
9 MySQL optimization MySQL optimize interview questions (2021 latest edition) Juejin. Cn/post / 695246…
10 JVM JVM Performance Tuning Interview questions (2021 Latest Edition) Juejin. Cn/post / 695246…
11 Linux Linux Interview Questions (2021 latest edition) Juejin. Cn/post / 695287…
12 Mybatis Mybatis (2021 latest Edition) Juejin. Cn/post / 695287…
13 Network programming TCP, UDP, Socket, Http Network programming interview (2021 latest edition) Juejin. Cn/post / 695287…
14 Design patterns Design Mode Interview Questions (2021 Latest edition) Juejin. Cn/post / 695544…
15 Big data 100 Big Data Interview Questions (2021 latest edition) Juejin. Cn/post / 695544…
16 Tomcat Tomcat Interview Questions (2021 Latest edition) Juejin. Cn/post / 695570…
17 multithreading Multithreaded Interview Questions (2021 Latest edition) Juejin. Cn/editor/draf…
18 Nginx Nginx_BIO_NIO_AIO interview Questions (2021 Latest edition) Juejin. Cn/editor/draf…
19 memcache Memcache Interview Questions (2021 latest edition) Juejin. Cn/post / 695608…
20 Java exception Java Exception Interview Questions (2021 Latest edition) Juejin. Cn/post / 695644…
21 The Java virtual machine Java Virtual Machine Interview (2021 latest edition) Juejin. Cn/post / 695658…
22 Java collection Java Set Interview Questions (2021 Latest edition) Juejin. Cn/post / 695684…
23 Git Git Git Command (2021) Juejin. Cn/post / 695692…
24 Elasticsearch Elasticsearch (2021 Latest Edition) Juejin. Cn/post / 695840…
25 Dubbo Dubbo Interview Questions (2021 Latest edition) Juejin. Cn/post / 695842…

First, basic knowledge

1. Why Dubbo?

With the further development of servitization, there are more and more services, and the invocation and dependency between services are more and more complex. Service-oriented Architecture (SOA) has been born, and a series of corresponding technologies have been derived. A service framework that encapsulates behavior such as service provision, service invocation, connection processing, communication protocol, serialization, service discovery, service routing, and log output. Thus a service governance framework for distributed systems emerged, and Dubbo was born.

2. What is Dubbo?

Dubbo is a high-performance, lightweight, open source RPC framework that provides efficient service governance solutions such as automatic service registration and automatic discovery. It can be seamlessly integrated with the Spring framework.

3. What are the usage scenarios of Dubbo?

  • Transparent remote method invocation: Remote methods are called just like local methods, with simple configuration and no API intrusion.
  • Soft load balancer and fault tolerance mechanism: It can replace hardware load balancers such as F5 on the Intranet to reduce costs and single points.
  • Automatic service registration and discovery: No longer need to write out the address of the service provider, the registry queries the IP address of the service provider based on the interface name, and can smoothly add or remove service providers.

4. What are the core functions of Dubbo?

  • Remoting: A network communication framework that abstracts various NIO frameworks, including synchronous to asynchronous and request-response information exchange modes. Cluster: Service framework that provides transparent remote procedure calls based on interface methods, including multi-protocol support, and Cluster support for soft load balancing, failure tolerance, address routing, and dynamic configuration.
  • Registry: service registration, based on the Registry directory service, so that service consumers can dynamically find service providers, so that addresses are transparent, so that service providers can smoothly add or subtract machines.

5. What are Dubbo’s core components?

  • Provider: exposes the service Provider of the service
  • Consumer: Invokes the remote service Consumer
  • Registry: Service registration and discovery Registry
  • Monitor: Monitors center and access call statistics
  • Container: service running Container

6. The process of Dubbo server registration and discovery?

  • The Service Container is responsible for starting, loading, and running the service provider.
  • The service Provider registers its services with the registry at startup.
  • At startup, a service Consumer subscribes to the registry for the services it needs.
  • 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 selects one provider from the provider address list to call based on the soft load balancing algorithm. If the call fails, it selects another one to call.
  • The service Consumer and Provider accumulate call times and call time in memory, and regularly send statistical data to Monitor every minute.

Second, architecture design

7. What are the layers of the overall architectural design of Dubbo?

  • Interface Service layer: This layer is related to business logic and designs corresponding interfaces and implementations according to the services of Provider and consumer
  • Configuration layer (Confifig) : external configuration interface, centered on ServiceConfifig and ReferenceConfifig
  • Proxy: transparent Proxy of the service interface, which generates the client Stub and server Skeleton of the service
  • The center is ServiceProxy, and the extended interface is ProxyFactory
  • Service Registration layer (Registry) : encapsulates the registration and discovery of service addresses, takes service URL as the center, and extends the interface as
  • RegistryFactory, Registry, RegistryService
  • Routing layer (Cluster) : encapsulates routing and load balancing for multiple providers and Bridges registries, centered on Invoker, with extended interfaces for Cluster, Directory, Router, and LoadBlancce
  • Monitoring layer (Monitor) : Monitors the number and time of RPC calls. It centers on Statistics and extends interfaces to MonitorFactory, Monitor, and MonitorService
  • Protocal (Protocal) : Encapsulates RPC calls with Invocation and Result centered and extends interfaces to Protocal, Invoker, and Exporter
  • Information Exchange layer (Exchange) : encapsulates the request response pattern, synchronous to asynchronous. Centered on Request and Response,
  • The expansion interfaces are Exchanger, ExchangeChannel, ExchangeClient and ExchangeServer
  • Network Transport Layer (Transport) : Abstract MINA and Netty as the unified interface, Message as the center, extended interfaces are Channel, Transporter, Client, Server and Codec
  • Serialize: Reusable tools with Serialization, ObjectInput, ObjectOutput, and ThreadPool extensions

8. How to implement Dubbo Monitor?

The Consumer goes through the fifilter chain before making the call. When receiving a request, the provider goes through the FIFilter chain first and then performs actual business logic processing. By default, Monitorfifilter is Monitorfifilter in both the consumer and provider fiFilter chains.

  1. MonitorFilter sends data to the DubboMonitor
  2. DubboMonitor temporarily stores aggregated data (within 1min by default) to ConcurrentMap

    statisticsMap, and then uses a single thread with 3 threads (thread name: The thread pool of DubboMonitorSendTimer calls SimpleMonitorService to traverse statisticsMap every 1min. Reset the AtomicReference of the current Statistics
    ,>
  3. SimpleMonitorService loads the aggregated data into BlockingQueue Queue (queue uppercase 100000)
  4. SimpleMonitorService using a background thread (thread called: DubboMonitorAsyncWriteLogThread) will be written to the file of data in the queue (this thread to write in the form of infinite loop)
  5. SimpleMonitorService also uses a thread pool of one thread (thread name: DubboMonitorTimer) to graph the statistics in the file every 5 minutes

Distributed framework

9. What other distributed frameworks are similar to Dubbo?

One of the best known is Spring Cloud.

10. What does Dubbo have to do with Spring Cloud?

  • Dubbo is a product of the SOA era, which focuses on service invocation, traffic distribution, traffic monitoring, and fusing. Spring Cloud was born in the era of microservices architecture, considering all aspects of microservices governance, and relying on
  • Based on the advantages of Spring and Spring Boot, the two frameworks have different goals at the beginning. Dubbo positioning service governance and Spring Cloud is to create an ecosystem.

12. The difference between a Dubbo and a Dubbox?

Dubbox is an extension project made by Dangdang based on Dubbo after Dubbo stopped maintenance, such as adding Restful service calls and updating open source components.

4. Registration Center

13. What registries does Dubbo have?

  • Multicast registries: The Multicast registries can register and discover services based on Multicast transmission in the network without any central node but only the broadcast address.
  • Zookeeper registry: Based on the distributed coordination system Zookeeper, the Watch mechanism of Zookeeper is used to change data.
  • Redis registry: Based on Redis, it uses key/ Map storage, key storage service name and type, key storage service URL in map, and value service expiration time. Redis-based publish/subscribe model notifies data changes.
  • Simple registry.
  • You are advised to use Zookeeper as the registry

14. Can publishers and subscribers communicate when Dubbo’s registry cluster is down?

  • It can communicate. When Dubbo is started, consumers will pull data such as the address interface of registered producers from Zookeeper and cache it locally. Each invocation is made according to the address of the local store.

Five, the cluster

15. What load balancing policies does the Dubbo cluster provide?

  • Random LoadBalance: Provider policies are randomly selected to dynamically adjust provider weights. The cross section collision rate is high, the more calls, the more uniform distribution.
  • RoundRobin LoadBalance: Indicates that provider policies are evenly distributed, but requests are accumulated.
  • LeastActive LoadBalance: LeastActive LoadBalance: the LeastActive call policy, the slower provider receives fewer requests.
  • ConstantHash LoadBalance: a consistent Hash policy that ensures that requests with the same parameters are always sent to the same provider. If a machine is down, it can be allocated to other providers based on virtual nodes to avoid drastic changes in providers.

16. What are Dubbo’s cluster fault tolerance schemes?

  • Failover Cluster: Automatically switches servers when a failure occurs. If a failure occurs, retry other servers. Typically used for read operations, but retries introduce longer delays.
  • Failfast Cluster: fails quickly. An error is reported immediately after the Failfast Cluster is invoked only once. Typically used for non-idempotent writes, such as new records.
  • Failsafe Cluster: indicates failure security. If an exception occurs, it is ignored. It is used to write audit logs.
  • Failback Cluster: Automatically recovers when a failure occurs. Failed requests are recorded in the background and resent periodically. Typically used for message notification operations.
  • Forking Cluster: Calls multiple servers in parallel and returns if one is successful. It is usually used for read operations that require high real-time performance but waste more service resources. The maximum parallelism can be set by forks= “2”.
  • Broadcast Cluster: Broadcasts calls to all providers one by one. An error is reported on any provider. Typically used to notify all providers to update local resource information such as caches or logs.

Six, configuration,

17. How is the Dubbo configuration file loaded into Spring?

When the Spring container is started, it reads some of Spring’s default schemas as well as Dubbo’s custom schemas. Each schema has its own NamespaceHandler. The NamespaceHandler resolves the configuration information with the BeanDefifinitionParser and converts it into the bean object that needs to be loaded.

18. What are the core configurations?

19. How to set Dubbo timeout?

Dubbo timeout can be set in two ways:

  • Set the timeout on the service provider side. In Dubbo’s user documentation, it is recommended to configure as much as you can on the service side, since the service provider is more aware of the service features it provides than the consumer.
  • Set the timeout period on the service consumer. If the timeout period is set on the service consumer, the service consumer has the highest priority. Because the service caller has more flexibility to set timeout control. If the consumer times out, the server thread does not customize and generates a warning.

20. What happens if the service invocation times out?

Dubbo will retry twice by default if the service invocation is unsuccessful.

7. Communication protocol

21. What communication framework does Dubbo use?

Netty is used as the communication framework by default.

22. What protocols does Dubbo support, and what are their strengths and weaknesses?

  • Dubbo: Single long connection and NIO asynchronous communication, suitable for large concurrent and small data volume service calls, and far more consumers than providers. TCP, asynchronous Hessian serialization. Dubbo The Dubbo protocol is recommended.
  • RMI: using JDK standard RMI protocol implementation, transmission parameters and return parameter objects need to implement Serializable interface, the use of Java standard serialization mechanism, the use of blocking short connection, transmission packet size mixed, the number of consumers and providers is about the same, can transfer files, transmission protocol TCP. Multiple short connection TCP transport, synchronous transport, suitable for general remote service calls and RMI interoperation. Java serialization suffers from security vulnerabilities when relying on earlier versions of the Common-Collections package.
  • WebService: Remote call protocol based on WebService, integrated with CXF implementation, providing interoperability with native WebService. Multiple short connections, HTTP based transmission, synchronous transmission, suitable for system integration and cross-language invocation.
  • HTTP: A remote invocation protocol based on HTTP form submission, implemented using Spring’s HttpInvoke. Multiple short connections, transport protocol HTTP, mixed sizes of incoming parameters, more providers than consumers, JS calls to applications and browsers.
  • Hessian: Integrated Hessian service, based on HTTP communication, using Servlet to expose the service, Dubbo embedded Jetty as the default implementation of the server, providing interoperation with Hession service. Multiple short connections, synchronous HTTP transfers, Hessian serialization, large incoming parameters, more providers than consumers, more provider pressure, passable files.
  • Memcache: RPC protocol based on Memcache implementation.
  • Redis: RPC protocol based on Redis

Viii. Design mode

23. What design patterns does Dubbo use?

Dubbo framework uses a variety of design patterns during initialization and communication, which can flexibly control functions such as class loading and permission control.

Ix. Operation and maintenance management

24. How can the service be compatible with the old version when it goes online?

You can transition to version, where multiple services of different versions are registered in the registry and services of different version numbers do not refer to each other. This is somewhat similar to the concept of service grouping.

25. What does the Dubbo Telnet command do?

After dubbo service is released, we can use Telnet command to debug and manage. Dubbo2.0.5 or later services provide ports that support Telnet commands

26. Are Dubbo support services degraded?

Set mock= “return NULL” via Dubbo: Reference. You can also change the mock value to true and implement a mock class in the same path as the interface, using the “interface name + mock” suffix. Then implement your own degradation logic in the Mock class

27. How does Dubbo stop gracefully?

Dubbo is implemented with JDK ShutdownHook for graceful shutdown, so if you use kill -9 PID or other forced shutdown commands, graceful shutdown will not be performed, only if you pass kill PID.

Ten, SPI

28. What is the difference between Dubbo SPI and Java SPI?

The JDK SPI:

The STANDARD SPI in the JDK loads all extension implementations at once, and if an extension is time-consuming but not used, it can be a waste of resources. So it’s not realistic to just want to load one implementation

DUBBO SPI:

1, to extend Dubbo, do not need to change the source of Dubbo

Lazy loading allows you to load only as many extensions as you want at a time.

3. Added support for extension points IOC and AOP, where one extension point can directly setter to inject other extension points.

4. Dubbo’s extension mechanism supports third-party IoC containers well, and Spring beans are supported by default.

Xi. Miscellaneous

29. Does Dubbo support distributed transactions?

  • Currently not supported and can be implemented with the TCC-Transaction framework
  • Tcc-transaction is an open source TCC compensatory distributed transaction framework
  • Tcc-transaction avoids its own intrusion into business code through Dubbo’s implicit parameter passing capability.

30. Can Dubbo cache results?

  • To improve the speed of data access. < Dubbo: Reference cache= “true” />
  • Cache = “true” cache= “true”

31. What packages must Dubbo rely on?

  • Dubbo must rely on JDK, otherwise optional.

32. What serialization methods does Dubbo support?

  • Hessian serialization is used by default. There are also Duddo, FastJson, and Java serialization.

33. What measures does Dubbo take in terms of safety?

  • Dubbo prevents users from directly connecting by bypassing the registry through Token tokens, and then manages authorization on the registry.
  • Dubbo also provides a blacklist and whitelist of services to control which callers are allowed by the service.

34. Is the service invocation blocking?

  • It blocks by default and can be called asynchronously, if there is no return value. Dubbo is a non-blocking parallel invocation based on NIO. The client can complete the parallel invocation of multiple remote services without starting multithreading. Compared with multithreading, the overhead is relatively small.

35. What is the mechanism by which service providers can implement fail-kick?

  • Service failure Kicks out temporary zooKeeper-based nodes.

36. Can I directly connect to a service when there are multiple registrations for the same service?

  • You can directly connect to a service point-to-point by modifying the configuration, or directly connect to a service through Telnet.

37. Dubbo service is degraded. What can I do if I try again?

  • Mock = “Return NULL” can be set in dubbo: Reference. You can also change the mock value to true and implement a mock class in the same path as the interface, using the “interface name + mock” suffix. Then implement your own degradation logic in the Mock class

38. What are the problems encountered during the use of Dubbo?

  • The corresponding service cannot be found in the registry. Check if the service implementation class has added the @service annotation and cannot connect to the registry. Check if the corresponding test IP in the configuration file is correct

Twelve, RPC

39. Why RPC

  • HTTP interface is a communication means often used in the early stage of information island in the case of few interfaces and less interaction between systems. The advantages are simplicity, directness and ease of development. Use the existing HTTP protocol for transport. However, if it is a large website with many internal subsystems and interfaces, the benefits of RPC framework will be shown. The first is the long link, which does not require three handshakes like HTTP for each communication, which reduces the network overhead. Secondly, RPC frameworks generally have registries and rich monitoring management. Publishing, offline interfaces, dynamic extensions, etc., are unaware and unified operations for callers. The third one is security. Finally, the recently popular servitization architecture, servitization governance, RPC framework is a strong support.
  • Socket is a simple way of network communication, only to create the communication channel between the two sides of the communication, and to achieve the function of RPC, it needs to be encapsulated to achieve more functions.
  • RPC is usually written with netty framework and Spring custom annotations to write a lightweight framework. In fact, Netty encapsulates sockets internally. The IO of newer JDK is generally NIO, that is, non-blocking IO

40. What is RPC

41. PRC architecture components

A basic RPC architecture should contain at least four components:

1. Client: service caller (service consumer)

2. Client Stub: Stores the address information of the service end, packages the request parameter information of the Client into network messages, and sends them to the service end through network transmission

3. The Server Stub receives the request message sent by the client, unpacks it, and then invokes the local service for processing. 4

Specific call process:

1. The service consumer invokes the service to be consumed by invoking the local service.

2. After receiving the call request, the client stub is responsible for serializing (assembling) information such as methods and input parameters into a message body that can be transmitted through the network.

3. The client stub finds the remote service address and sends the message to the server over the network.

4. The server stub decodes the message after receiving it (deserialization operation);

5. The server stub invokes the local service for relevant processing according to the decoding result;

6. The local service executes the specific business logic and returns the processing result to the server stub.

7. The server stub repackages the returned result into a message (serialized) and sends it to the consumer over the network;

8. The client stub receives the message and decodes (deserializes) it.

9. The service consumer gets the final result;

42. Differences between RPC and SOA, SOAP, REST

1, the REST

It can be seen as a direct application of HTTP protocol. By default, it is based on JSON as the transmission format. It is simple to use, low cost to learn, high efficiency, but low security.

2, the SOAP

SOAP is a data exchange protocol specification that is a lightweight, simple, XML-based protocol specification. SOAP can be seen as a heavyweight protocol, based on XML, SOAP Security is through the use of XML-Security and XML-signature two specifications formed ws-Security to achieve Security control, has been supported by various manufacturers. What are its advantages? Simple summary: easy to use, flexible, cross-language, cross-platform.

3, SOA

A service-oriented architecture that enables distributed deployment, composition, and use of loosely coupled, coarse-grained application components over a network as required. The service layer is the foundation of SOA and can be invoked directly by applications to effectively control the artificial dependencies in the system that interact with software agents. SOA is a coarse-grained, loosely coupled service architecture in which services communicate with each other through simple, precisely defined interfaces, without involving underlying interfaces and communication models. SOA can be seen as a natural extension of the B/S model, XML (a subset of standard Common Markup Language) /Web Services technology.

What is the difference between REST and SOAP and RPC?

There is not much difference between them. Their essence is to provide basic services that can support distribution. The biggest difference lies in the different application scenarios brought by their respective characteristics.

43. What problems need to be solved by RPC framework?

1. How to determine the communication protocol between the client and the server?

2. How to make network communication more efficient?

3. How are the services provided by the server exposed to the client?

4. How does the client discover these exposed services?

5. How to serialize and deserialize request objects and response results more efficiently?

44. The implementation basis of RPC?

1. Highly efficient network communication is required. For example, Netty is generally selected as the network communication framework.

2. Need a more efficient serialization framework, such as Google’s Protobuf serialization framework;

3. Reliable addressing (mainly for service discovery), such as using Zookeeper to register services, etc.

4, if it is RPC call with session (state), also need to have session and state hold function;

45. What key technologies does RPC use?

1. Dynamic proxy

The Java dynamic proxy technology is used when generating Client stubs and Server stubs. You can use either the native dynamic proxy mechanism provided by JDK or the open source CGLib proxy or Javassist bytecode generation technology.

Serialization and deserialization

On a network, all data will be converted to bytes for transmission, so parameters need to be serialized and deserialized in order to be able to be transmitted over the network. Serialization: The process of converting an object into a sequence of bytes is called object serialization, which is the process of encoding. Deserialization: The process of restoring a sequence of bytes to an object is called deserialization of an object, which is the process of decoding. Current efficient open source serialization frameworks: Kryo, FastJson, Protobuf, etc. Deserialization: The process of restoring a sequence of bytes to an object is called deserialization of an object, which is the process of decoding. Current efficient open source serialization frameworks: Kryo, FastJson, Protobuf, etc.

3. NIO communication

Traditional blocking IO is not suitable for concurrency performance, so we need asynchronous IO, or NIO. Java provides a solution to NIO, and Java 7 provides better NIO.2 support. You can choose Netty or MINA to solve NIO data transfer problems.

4. Service registry

Optional: Redis, Zookeeper, Consul, Etcd. ZooKeeper is generally used to register and discover services and solve single point of failure and distributed deployment problems (registries).

46. What are the mainstream RPC frameworks

47. Implementation principle architecture diagram of RPC

That is to say, two servers A and B have one application deployed on server A. If they want to call the function/method provided by the application on server B, they cannot call it directly because they do not have the same memory space. Therefore, they need to express the call semantics and transfer the call data over the network.

For example, server A wants to call A method on server B:

1. Establish communication

The problem of communication needs to be solved first: that is, if machine A wants to call machine B, it must establish A communication connection. This is done primarily by establishing a TCP connection between the client and the server, where all data exchanged by a remote procedure call is transmitted. A connection can be an on-demand connection that breaks after the call, or a long connection that is shared by multiple remote procedure calls. Usually this connection can be on-demand connection (you need to call when they first establish a connection, immediately after the call breaking), can also be a long connection (client and server to establish connection to maintain long-term holding, or when any packets to send, can cooperate with heartbeat detection mechanism regularly check whether the connection of the established effective survival). Multiple remote procedure calls share the same connection.

2. Service addressing

To solve the problem of addressing, that is, how the application on server A tells the underlying RPC framework how to connect to server B (such as A host or IP address) and the specific port, what the name of the method is. Usually we need to provide the B machine (hostname or IP address) and a specific port, and then specify the name of the method or function to be called and the input and output parameters to complete a call to the service. Reliable addressing (primarily for the discovery of services) is a cornerstone of RPC’s implementation, such as registering services using Redis or Zookeeper.

2.1 From the perspective of service providers:

When a service provider is started, it needs to register its services with the specified registry so that service consumers can search through the service registry. When the service provider stops providing the service for various reasons, it needs to unregister the stopped service to the registry. The service provider needs to send heartbeat detection to the service registry periodically. If the service registry considers that the service provider has stopped the service after not receiving heartbeat from the service provider for a period of time, the service registry will remove the service from the registry.

2.2 From the perspective of the caller:

When the service is started, the caller looks up the address of the service provider to the service registry according to the service he subscribes to.

When a service consumed by a service caller goes online or offline, the registry notifies the service caller;

When the service caller goes offline, the subscription is unsubscribed.

3. Network transmission

3.1 serialization

When the application on machine A initiates an RPC call, the information about the calling method and its input parameters needs to be transmitted to machine B through the underlying network protocol, such as TCP. As the network protocol is based on binary, All the data we transmit needs to be serialized or marshaled into binary before it can be transmitted over the network. The serialized or marshalled binary data is then sent to machine B through addressing operations and network transport.

3.2 deserialization

When machine B receives the request from the application of machine A, it needs to deserialize the received parameters and other information (the reverse operation of serialization), that is, restore the binary information to the expression in memory. Then find the corresponding method (part of the address) to make the local call (usually through Proxy generation, usually including JDK dynamic Proxy, CGLIB dynamic Proxy, Javassist bytecode generation technology, etc.), and get the return value of the call.

4. Service invocation

B machine for local calls (through the Proxy agent and reflection calls) after received the return value, at this time also need to be sent back to the return value is A machine, also need the serialized operation, and then through the network to send binary data back to A machine, and when A machine to receive these return values, deserialize operation again, It is restored to an in-memory representation and finally handed over to the application on machine A for relevant processing (generally business logic processing operations).