W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
Kitex 默認集成了自研的高性能網(wǎng)絡(luò)庫 Netpoll,但沒有與 Netpoll 強綁定,同時也支持使用者擴展其他網(wǎng)絡(luò)庫按需選擇。Kitex 還提供了 ShmIPC 進一步提升 IPC 性能,該擴展會在后續(xù)開源。
傳輸模塊主要的擴展接口如下:
type TransServer interface {...}
type ServerTransHandler interface {...}
type ClientTransHandler interface {...}
type ByteBuffer interface {...}
type Extension interface {...}
// -------------------------------------------------------------
// TransServerFactory is used to create TransServer instances.
type TransServerFactory interface {
NewTransServer(opt *ServerOption, transHdlr ServerTransHandler) TransServer
}
// ClientTransHandlerFactory to new TransHandler for client
type ClientTransHandlerFactory interface {
NewTransHandler(opt *ClientOption) (ClientTransHandler, error)
}
// ServerTransHandlerFactory to new TransHandler for server
type ServerTransHandlerFactory interface {
NewTransHandler(opt *ServerOption) (ServerTransHandler, error)
}
TransServer 是服務(wù)端的啟動接口,ServerTransHandler 和 ClientTransHandler 分別是服務(wù)端和調(diào)用端對消息的處理接口,ByteBuffer 是讀寫接口。相同的 IO 模型下 TransHandler 的邏輯通常是一致的,Kitex 對同步 IO 提供了默認實現(xiàn)的 TransHandler,針對不一樣的地方抽象出了 Extension 接口,所以在同步 IO 的場景下不需要實現(xiàn)完整的 TransHandler 接口,只需實現(xiàn) Extension 即可。
如下是 Kitex 對 Netpoll 同步 IO 的擴展,分別實現(xiàn)了Extension、ByteBuffer、TransServer 接口。
option: ?WithTransServerFactory
?, ?WithTransHandlerFactory
?
var opts []server.Option
opts = append(opts, server.WithTransServerFactory(yourTransServerFactory)
opts = append(opts, server.WithTransHandlerFactory(yourTransHandlerFactory)
svr := xxxservice.NewServer(handler, opts...)
option: ?WithTransHandlerFactory
?
cli, err := xxxservice.NewClient(targetService, client.WithTransHandlerFactory(yourTransHandlerFactory)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: