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

Kitex Transport Pipeline-Bound 擴(kuò)展

2022-04-27 10:39 更新

Transport Pipeline 參考 Netty ChannelPipeline,提供 Inbound 和 Outbound 接口,支持對消息或 I/O 事件擴(kuò)展?;?nbsp;In/OutboundHandler 可以擴(kuò)展實(shí)現(xiàn) TLS、限流、透傳信息處理等。如下圖所示,各個(gè) BoundHandler 會串行依次執(zhí)行。


接口定義

// OutboundHandler is used to process write event.
type OutboundHandler interface {
  Write(ctx context.Context, conn net.Conn, send Message) (context.Context, error)
}

// InboundHandler is used to process read event.
type InboundHandler interface {
  OnActive(ctx context.Context, conn net.Conn) (context.Context, error)

  OnInactive(ctx context.Context, conn net.Conn) context.Context

  OnRead(ctx context.Context, conn net.Conn) (context.Context, error)

  OnMessage(ctx context.Context, args, result Message) (context.Context, error)
}

默認(rèn)擴(kuò)展

  • 服務(wù)端限流 Handler

Kitex 支持連接級別和請求級別限流,限流是為了保障服務(wù)的可用性,當(dāng)達(dá)到閾值應(yīng)當(dāng)及時(shí)限流,放到 Transport 層可以達(dá)到及時(shí)限流的目的,實(shí)現(xiàn)見 limiter_inbound.go。

  • 連接級別限流 OnActive(), OnInactive()
  • 請求級別限流 OnRead()
  • 元信息透傳 Handler

元信息透傳是基于傳輸協(xié)議透傳一些 RPC 額外的信息給下游,同時(shí)讀取傳輸協(xié)議中上游透傳的信息,實(shí)現(xiàn)見 transmeta_bound.go。

  • 寫入透傳信息 Write()
  • 讀取透傳信息 OnMessage()

為更明確的為使用者元信息透傳的擴(kuò)展能力,Kitex 單獨(dú)定義了信息透傳的處理接口 MetaHandler,這里會執(zhí)行 MetaHandler 進(jìn)行透傳信息的處理。

// MetaHandler reads or writes metadata through certain protocol.
type MetaHandler interface {
  WriteMeta(ctx context.Context, msg Message) (context.Context, error)
  ReadMeta(ctx context.Context, msg Message) (context.Context, error)
}

指定自定義的 BoundHandler 

  • 服務(wù)端

option: ?WithBoundHandler?

svr := xxxservice.NewServer(handler, server.WithBoundHandler(yourBoundHandler))

  • 調(diào)用端

option: ?WithBoundHandler?

cli, err := xxxservice.NewClient(targetService, client.WithBoundHandler(yourBoundHandler))


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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號