国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

Kitex 傳輸模塊擴(kuò)展

2022-04-27 10:37 更新

Kitex 默認(rèn)集成了自研的高性能網(wǎng)絡(luò)庫(kù) Netpoll,但沒有與 Netpoll 強(qiáng)綁定,同時(shí)也支持使用者擴(kuò)展其他網(wǎng)絡(luò)庫(kù)按需選擇。Kitex 還提供了 ShmIPC 進(jìn)一步提升 IPC 性能,該擴(kuò)展會(huì)在后續(xù)開源。

擴(kuò)展接口 

傳輸模塊主要的擴(kuò)展接口如下:

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ù)端的啟動(dòng)接口,ServerTransHandler 和 ClientTransHandler 分別是服務(wù)端和調(diào)用端對(duì)消息的處理接口,ByteBuffer 是讀寫接口。相同的 IO 模型下 TransHandler 的邏輯通常是一致的,Kitex 對(duì)同步 IO 提供了默認(rèn)實(shí)現(xiàn)的 TransHandler,針對(duì)不一樣的地方抽象出了 Extension 接口,所以在同步 IO 的場(chǎng)景下不需要實(shí)現(xiàn)完整的 TransHandler 接口,只需實(shí)現(xiàn) Extension 即可。

Netpoll 的擴(kuò)展 

如下是 Kitex 對(duì) Netpoll 同步 IO 的擴(kuò)展,分別實(shí)現(xiàn)了Extension、ByteBuffer、TransServer 接口。


指定自定義的傳輸模塊

  • 服務(wù)端

option: ?WithTransServerFactory?, ?WithTransHandlerFactory?

var opts []server.Option
opts = append(opts, server.WithTransServerFactory(yourTransServerFactory)
opts = append(opts, server.WithTransHandlerFactory(yourTransHandlerFactory)

svr := xxxservice.NewServer(handler, opts...)

  • 調(diào)用端

option: ?WithTransHandlerFactory?

cli, err := xxxservice.NewClient(targetService, client.WithTransHandlerFactory(yourTransHandlerFactory)


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)