当前位置:网站首页>[translation] Introduction to go RPC: Hello World
[translation] Introduction to go RPC: Hello World
2022-07-24 00:08:00 【51CTO】

RPC(Remote Procedure Call) Short for remote procedure call , It is a popular communication mode between different nodes in distributed system . In the age of the Internet ,RPC Has been and IPC Become an indispensable basic component . therefore Go The standard library of language also provides a simple RPC Realization : net/rpc package .
RPC The purpose of is to become the function call mode of network system . Client execution RPC It's like calling a native function , They just package the function parameters and send them to the server through the network . The server can then unpack these parameters and process the request , Execute the result back to the client .
In computer science , Remote procedure call (RPC) It's a kind of interprocess communication , It allows computer programs to make subroutines or procedures in another address space ( Usually on another computer on a shared network ) perform , There is no need for programmers to explicitly code the details of this remote interaction . in other words , Whether the subroutine is a local program or a remote program that executes the program , Programmers write basically the same code . When the software in question uses object-oriented principles ,RPC It is called remote call or remote method call .
RPC edition Hello World
because net/rpc It provides us with a way for one piece of code to communicate with another piece of code through the network , A natural example is the client - In server architecture “Hello World”.
The code structure :
server.go
HelloWorld The method needs to meet GO Language RPC The rules , Receive two parameters , The second parameter is the pointer type , Return to one Error type , It must be a public method .HelloWorldService Type objects are registered to RPC service RPC.REGISTER Function call Register object methods in object types to RPC As in the rule RPC function , All registration methods are placed in HelloWorldService Under the service space TCP link , adopt rpc.serverConn Function is provided on this link RPC service :
client.go
adopt rpc.dial Of RPC Dial up service through client.call Call the specific method. The first parameter in the method is RPC Service name and method name , The second and third parameters are contained in the method .
边栏推荐
- DGS's mutations
- logback
- 【微服务架构】分布式事务
- What is restful verb
- PushGateway+Prometheus+Grafana构建Flink实时监控
- Beijing University qingniaochangping Campus: how about the current situation of operation and maintenance employment? Are skills required?
- STL case - judges' scoring
- 在原生终端实现类似 rz、sz 上传下载文件与目录的功能
- Qt | 设置部件大小 sizeHint、minimumSizeHint、sizePolicy、stretch factor
- STM32 can initialization details
猜你喜欢

Windows software: how to install mysql5.7 and configure environment variables
![[hcip] OSPF experiment under mGRE environment, including multi process bidirectional republication and OSPF special area](/img/9b/f40054d91bda3a018e29b106ccd8bb.jpg)
[hcip] OSPF experiment under mGRE environment, including multi process bidirectional republication and OSPF special area

Structured streaming programming model (input table, result table, output mode...)
QT | set part size sizehint, minimumsizehint, sizepolicy, stretch factor

【OpenCV】- cv.threshold()函数的参数type是数字时,代表的含义

Splicing of.Net distribution with outlook mail format and table

力扣刷题训练之超简单

FPGA - SPI bus control flash (3) including code

权重分析——熵权法

为什么大多数人都认为编程很难?
随机推荐
Is it safe to find an account manager to open a fund account online??
Chapter 5: implementation of Web adapter
Scheme for importing XMIND use cases into tapd (with code)
作为一个程序员,有什么想对新人说的吗?
STM32 can initialization details
Linked list - 707. Design linked list
Xmind用例导入到TAPD的方案(附代码)
进步成长的快乐
473-82(40、662、31、98、189)
idea无法切换成中文
Browser cannot access Minio
子矩阵的和
DGS file upload
My meeting of OA project (query)
The world's smallest material ranking, Lingzi, Xianzi, quark
pthread 的 joinable 和 detached
Chapter III Organization Code
Chapter 6: implement a persistence adapter
Windows软件:如何安装Mysql5.7并配置环境变量
474-82(8、221、300)