Chapter 4 RPC Call
RPC emerged to solve this problem.
RPC: What we often call remote procedure call is to call a remote method just like calling a local method. Most of the communication protocols are Binary way.
Commonly used RPC frameworks include (those marked in bold are intended to be explained):
-
gRPC
gRPC is a modern, open source, high-performance remote procedure call (RPC) framework that can run in any environment. It efficiently connects services within and across data centers, supporting load balancing, tracing, health checks, and authentication. It is also suitable for distributed computing, connecting devices, mobile applications and browsers to back-end services—this is the official description
-
openFeign
Simplify the HttpClient calling process and make net core development easier.
-
Thrift
Thrift is an interface description language and binary communication protocol that is used to define and create cross-language services. It is used as a remote procedure call (RPC) framework and was developed by Facebook for “large-scale cross-language service development”. It combines a software stack through a code generation engine to create varying degrees of seamless cross-platform efficient services using C#, C++, Cappuccino, Cocoa, Delphi, Erlang, Go, Haskell, Java, Node.js, OCaml, Perl, PHP, Python, Ruby and Smalltalk.
-
Shuttler.net
Shuttler.Net is a high-performance distributed framework. If you are using the old remoting, webservices distributed architecture, Or if you are using the new wcf, you can also try Shuttler.Net. If you want to develop your own IM server and client (or game lobby), you can also use Shuttler.Net, as long as you specify Just use the message protocol, and Shuttler will help you with other transport layers. Artery, the core component of Shuttler.Net, is just like its name: Pulse, a Tcp-based application stack that can help you transmit any energy, allowing you to sing whenever you want.
Main function points include:
-
Distributed RPC currently supports Tcp and Http (REST-like) dual channels (see Demo: TcpRpcTest and HttpRpcTest): There can be multiple RpcServers and multiple RpcClients, where the client calculates the server based on the Key through HashingAlgorithm.
-
Distributed cache system (Memcached), including MemcachedServer and MemcachedClient (see Demo: MemcachedTest): There can be multiple MemcachedServers and multiple MemcachedClients, where the client calculates the server based on the Key through HashingAlgorithm.
-
IM protocol stack, using the Artery component of Shuttler.Net can easily implement an IMServer and IMClient (see Demo: IMTest ): IMTest implements IM login password verification. You can define the communication protocol yourself. For protocol demo, see Shuttler_Artery_Protocol.
-
1. gRPC detailed tutorial
Official website: https://grpc.io
The main advantages of gRPC are:
-
Modern high-performance lightweight128, 1)”>1,
//This application External network protocol, http or https
“protocol“: “http“,
//This application External port number, such as 5000
“port“: 5000}
2. Access nacos service center
// Abandon native Nacos register // builder. Services.AddNacosAspNet(builder.Configuration); builder.Services.AddSummerBoot(); builder.Services.AddSummerBootFeign(p => { p.AddNacos(builder.Configuration); //Feign component is connected to Nacos });
3. Define the interface
namespace NetCloud.RpcClient { [FeignClient( ServiceName = "NetCloud .Nacos.UserService" , NacosNamespaceId = " NetCloud" , NacosGroupName = " DEFAULT_GROUP" , MicroServiceMode = true ) ] public interface span> IUserServiceClient { [GetMapping(" /User/GetUserList")] Task<List> GetUserList(); } }
At the same time, ServiceName, NacosGroupName, and NacosNamespaceId also support reading from the configuration file, such as
{ "ServiceName span>": "NetCloud.Nacos.UserService", "NacosGroupName span>": "DEFAULT_GROUP", "NacosNamespaceId span>": "NetCloud" } [FeignClient( ServiceName = "${ServiceName}", MicroServiceMode = true,NacosGroupName = "${NacosGroupName}", NacosNamespaceId = "${NacosNamespaceId}")] public interface span>IFeignService { [GetMapping(" /home/index")] Task<string> TestGet(); }
Video supporting link: Course Introduction (cctalk.com)
The sea is broad and the fish are leaping, the sky is high and I can do whatever I want. Give me a piece of blue sky and let me fly freely., 1)”>${NacosGroupName}“, NacosNamespaceId = “${NacosNamespaceId}“)]
public interface span>IFeignService
{
[GetMapping(“ /home/index“)]
Task<string> TestGet();
}
Video supporting link: Course Introduction (cctalk.com)
The sea is broad and the fish are leaping, the sky is high and I can do whatever I want. Give me a piece of blue sky and let me fly freely.