一个高效、可扩展且易于使用的 RPC 框架。
eRPC is an efficient, extensible and easy-to-use RPC framework.
Suitable for RPC, Microservice, Peer-to-Peer, IM, Game and other fields.
go vesion ≥ 1.18
install
GO111MODULE=on go get -u -v -insecure github.com/andeya/erpc/v7
import "github.com/andeya/erpc/v7"
Header and the BodyHeader contains metadata in the same format as HTTP headerBody supports for custom codec of Content Type-Like, already implemented:rawproto - Default high performance binary protocoljsonproto - JSON message protocolpbproto - Ptotobuf message protocolthriftproto - Thrift message protocolhttproto - HTTP message protocoltcptcp4tcp6unixunixpacketkcpquicSelf Test
A server and a client process, running on the same machine
CPU: Intel Xeon E312xx (Sandy Bridge) 16 cores 2.53GHz
Memory: 16G
OS: Linux 2.6.32-696.16.1.el6.centos.plus.x86_64, CentOS 6.4
Go: 1.9.2
Message size: 581 bytes
Message codec: protobuf
Sent total 1000000 messages
erpc
Comparison Test
EnvironmentThroughputsMean LatencyP99 Latency…
…
NOTE:
SetReadLimit// Start a server
var peer1 = erpc.NewPeer(erpc.PeerConfig{
ListenPort: 9090, // for server role
})
peer1.Listen()
...
// Start a client
var peer2 = erpc.NewPeer(erpc.PeerConfig{})
var sess, err = peer2.Dial("127.0.0.1:8080")
type Aaa struct {
erpc.CallCtx
}
func (x *Aaa) XxZz(arg *<T>) (<T>, *erpc.Status) {
...
return r, nil
}
// register the call route
// HTTP mapping: /aaa/xx_zz
// RPC mapping: Aaa.XxZz
peer.RouteCall(new(Aaa))
// or register the call route
// HTTP mapping: /xx_zz
// RPC mapping: XxZz
peer.RouteCallFunc((*Aaa).XxZz)
The default mapping(HTTPServiceMethodMapper) of struct(func) name to service methods:
AaBb -> /aa_bbABcXYz -> /abc_xyzAa__Bb -> /aa_bbaa__bb -> /aa_bbABC__XYZ -> /abc_xyzAa_Bb -> /aa/bbaa_bb -> /aa/bbABC_XYZ -> /abc/xyzerpc.SetServiceMethodMapper(erpc.HTTPServiceMethodMapper)
The mapping(RPCServiceMethodMapper) of struct(func) name to service methods:
AaBb -> AaBbABcXYz -> ABcXYzAa__Bb -> Aa_Bbaa__bb -> aa_bbABC__XYZ -> ABC_XYZAa_Bb -> Aa.Bbaa_bb -> aa.bbABC_XYZ -> ABC.XYZerpc.SetServiceMethodMapper(erpc.RPCServiceMethodMapper)
func XxZz(ctx erpc.CallCtx, arg *<T>) (<T>, *erpc.Status) {
...
return r, nil
}
// register the call route
// HTTP mapping: /xx_zz
// RPC mapping: XxZz
peer.RouteCallFunc(XxZz)
type Bbb struct {
erpc.PushCtx
}
func (b *Bbb) YyZz(arg *<T>) *erpc.Status {
...
return nil
}
// register the push handler
// HTTP mapping: /bbb/yy_zz
// RPC mapping: Bbb.YyZz
peer.RoutePush(new(Bbb))
// or register the push handler
// HTTP mapping: /yy_zz
// RPC mapping: YyZz
peer.RoutePushFunc((*Bbb).YyZz)
// YyZz register the handler
func YyZz(ctx erpc.PushCtx, arg *<T>) *erpc.Status {
...
return nil
}
// register the push handler
// HTTP mapping: /yy_zz
// RPC mapping: YyZz
peer.RoutePushFunc(YyZz)
func XxxUnknownCall (ctx erpc.UnknownCallCtx) (interface{}, *erpc.Status) {
...
return r, nil
}
// register the unknown call route: /*
peer.SetUnknownCall(XxxUnknownCall)
func XxxUnknownPush(ctx erpc.UnknownPushCtx) *erpc.Status {
...
return nil
}
// register the unknown push route: /*
peer.SetUnknownPush(XxxUnknownPush)
…
// add router group
group := peer.SubRoute("test")
// register to test group
group.RouteCall(new(Aaa), NewIgnoreCase())
peer.RouteCallFunc(XxZz, NewIgnoreCase())
group.RoutePush(new(Bbb))
peer.RoutePushFunc(YyZz)
peer.SetUnknownCall(XxxUnknownCall)
peer.SetUnknownPush(XxxUnknownPush)
…
SetMessageSizeLimit sets max message size. If maxSize<=0, set it to max uint32.
func SetMessageSizeLimit(maxMessageSize uint32)
SetSocketKeepAlive sets whether the operating system should send keepalive messages on the connection.
func SetSocketKeepAlive(keepalive bool)
SetSocketKeepAlivePeriod sets period between keep alives.
func SetSocketKeepAlivePeriod(d time.Duration)
SetSocketNoDelay controls whether the operating system should delay message transmission in hopes of sending fewer messages (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.
func SetSocketNoDelay(_noDelay bool)
SetSocketReadBuffer sets the size of the operating system's receive buffer associated with the connection.
func SetSocketReadBuffer(bytes int)
SetSocketWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
func SetSocketWriteBuffer(bytes int)
"github.com/andeya/erpc/v7/codec"
JSON codec(erpc own)
protobuf
"github.com/andeya/erpc/v7/codec"
Protobuf codec(erpc own)
thrift
"github.com/andeya/erpc/v7/codec"
Form(url encode) codec(erpc own)
xml
"github.com/andeya/erpc/v7/codec"
Form(url encode) codec(erpc own)
plain
"github.com/andeya/erpc/v7/codec"
Plain text codec(erpc own)
form
"github.com/andeya/erpc/v7/codec"
Form(url encode) codec(erpc own)
"github.com/andeya/erpc/v7/plugin/auth"
An auth plugin for verifying peer at the first time
binder
"github.com/andeya/erpc/v7/plugin/binder"
Parameter Binding Verification for Struct Handler
heartbeat
"github.com/andeya/erpc/v7/plugin/heartbeat"
A generic timing heartbeat plugin
proxy
"github.com/andeya/erpc/v7/plugin/proxy"
A proxy plugin for handling unknown calling or pushing
secure
"github.com/andeya/erpc/v7/plugin/secure"
Encrypting/decrypting the message body
overloader
"github.com/andeya/erpc/v7/plugin/overloader"
A plugin to protect erpc from overload
"github.com/andeya/erpc/v7/proto/rawproto
A fast socket communication protocol(erpc default protocol)
[jsonproto](https://github.com/andeya/erpc/tree/master/prot
暂无开放 Issues,或尚未同步最近议题。