当前位置: 首页 > news >正文

国外自助建站百度在线

国外自助建站,百度在线,网站页面开发流程,wordpress集中管理codec 包基础设计 package:trpc-go/codec Msg接口的定义: 后续实际的消息msg结构体实现该接口,可以方便地获取一些值(如Context),也可以方便地进行一些值地设置(如设置SerializationType) //…

codec 包基础设计

package:trpc-go/codec

  1. Msg接口的定义: 后续实际的消息msg结构体实现该接口,可以方便地获取一些值(如Context),也可以方便地进行一些值地设置(如设置SerializationType)
// message.go 文件下 // Msg defines core message data for multi protocol, business protocol
// should set this message when packing and unpacking data.
type Msg interface {// Context returns rpc contextContext() context.Context// WithRemoteAddr sets upstream address for server,// or downstream address for client.WithRemoteAddr(addr net.Addr)// WithLocalAddr sets server local address.WithLocalAddr(addr net.Addr)// RemoteAddr returns upstream address for server,// or downstream address for client.RemoteAddr() net.Addr// LocalAddr returns server local address.LocalAddr() net.Addr// WithNamespace sets server namespace.WithNamespace(string)// Namespace returns server namespace.Namespace() string// WithEnvName sets server environment.WithEnvName(string)// SerializationType returns serialization type.SerializationType() int// WithCompressType sets compress type.WithCompressType(int)....
  1. msg 整个rpc的上下文,先看接口体的设计,以及实现上面Msg接口定义的方法
// message_impl.go 文件// msg is the context of rpc.
type msg struct {context             context.ContextframeHead           interface{}requestTimeout      time.DurationserializationType   intcompressType        intstreamID            uint32dyeing              booldyeingKey           stringserverRPCName       stringclientRPCName       stringserverMetaData      MetaDataclientMetaData      MetaDatacallerServiceName   stringcalleeServiceName   stringcalleeContainerName stringserverRspErr        errorclientRspErr        errorserverReqHead       interface{}serverRspHead       interface{}clientReqHead       interface{}clientRspHead       interface{}localAddr           net.AddrremoteAddr          net.Addrlogger              interface{}callerApp           stringcallerServer        stringcallerService       stringcallerMethod        stringcalleeApp           stringcalleeServer        stringcalleeService       stringcalleeMethod        stringnamespace           stringsetName             stringenvName             stringenvTransfer         stringrequestID           uint32calleeSetName       stringstreamFrame         interface{}commonMeta          CommonMetacallType            RequestType
}// 实现了 Msg接口所有方法
// Context restores old context when create new msg.
func (m *msg) Context() context.Context {return m.context
}// WithNamespace set server's namespace.
func (m *msg) WithNamespace(namespace string) {m.namespace = namespace
}
....

msg在后续:会被写入trpc协议的帧头中,进行网络传输,以达到下游
在这里插入图片描述

客户端调用 使用message:GreeterClientProxyImpl

  1. 客户端调用具体rpc方法桩代码:
func (c *GreeterClientProxyImpl) Hello(ctx context.Context, req *HelloRequest, opts ...client.Option) (*HelloReply, error) {// 派生出新的消息,以实现整个调用链路的context消息传递ctx, msg := codec.WithCloneMessage(ctx)defer codec.PutBackMessage(msg)msg.WithClientRPCName("/trpc.helloworld.Greeter/Hello")msg.WithCalleeServiceName(GreeterServer_ServiceDesc.ServiceName)msg.WithCalleeApp("")msg.WithCalleeServer("")msg.WithCalleeService("Greeter")msg.WithCalleeMethod("Hello")msg.WithSerializationType(codec.SerializationTypePB)callopts := make([]client.Option, 0, len(c.opts)+len(opts))callopts = append(callopts, c.opts...)callopts = append(callopts, opts...)rsp := &HelloReply{}if err := c.client.Invoke(ctx, req, rsp, callopts...); err != nil {return nil, err}return rsp, nil
}

先看WithCloneMessage方法:主要实现一组新的 ctx 和 msg 的派生

  • 首先可以看到第二个返回值Msg就是之前的接口类型
  • val.(*msg)是因为context中存储的不是实际结构体,而是结构体的指针
  • 所以上面桩代码中:msg.WithClientRPCName(“/trpc.helloworld.Greeter/Hello”),WithClientRPCName这些方法都是指针类型的实现:func (m *msg) xxx(namespace string) {
// message_impl.go 文件// WithCloneMessage copy a new message and put into context, each rpc call should
// create a new message, this method will be called by client stub.
func WithCloneMessage(ctx context.Context) (context.Context, Msg) {newMsg := msgPool.Get().(*msg)val := ctx.Value(ContextKeyMessage)m, ok := val.(*msg)if !ok {ctx = context.WithValue(ctx, ContextKeyMessage, newMsg)newMsg.context = ctxreturn ctx, newMsg}ctx = context.WithValue(ctx, ContextKeyMessage, newMsg)newMsg.context = ctxcopyCommonMessage(m, newMsg)copyServerToClientMessage(m, newMsg)return ctx, newMsg
}

到这里,一个派生的消息就从一个现有消息中拷贝了框架定义的一些上下文信息了,并且也设置了主调信息为自身服务,但是,被调信息呢?你回到开头看 tRPC 的桩代码就会知道了,桩代码里会负责进一步重写被调信息。

参考文献:

https://cloud.tencent.com/developer/article/2417507

http://www.cadmedia.cn/news/13144.html

相关文章:

  • 做购物网站哪家公司好百度 营销推广多少钱
  • 智慧团建系统登录入口官网广州百度seo代理
  • 网站源码下载音乐网址和网站的区别
  • 网站建设哪个空间比较好设计师培训班多少钱
  • 第二章营销型网站建设测验网站搜索引擎推广
  • 建设公司网站建设报价分析影响网站排名的因素
  • 学校校园网站建设方案百度移动版
  • 找能做网站的推广员网站
  • 武汉肥猫科技商城网站建设一个完整的营销策划方案范文
  • 有做机械工装的网站吗做网站建设优化的公司排名
  • 江苏高端网站建设华为seo诊断及优化分析
  • 海西州电子商务网站建设公司全球网站访问量排名
  • 专业免费网站建设哪里便宜关键词优化分析工具
  • 网站建设实施背景分析百度下载免费
  • 飞行时代网站建设利尔化学股票股吧
  • 成都住房和城乡建设部网站查询北京债务优化公司
  • cnd设计网官网seo在线优化平台
  • wordpress注册用户可见东莞seo建站投放
  • 国外购物网站app线下推广有哪些渠道
  • 济南烨铭网站建设谷歌推广外贸建站
  • 网站建设项目策划石家庄百度快照优化
  • 今日重大财经新闻网站推广优化方式
  • 营口东站营销网站建设免费广州seo
  • 如何选择宜昌网站建设班级优化大师学生版
  • 网站建设项目的运行与测试报告云优客seo排名公司
  • 中小企业网站制作费用义乌百度广告公司
  • 沧州网站建设建站系统最近实时热点新闻事件
  • 广州市新冠疫情最新消息windows优化大师是官方的吗
  • 自己建的网站如何推广如何自己开发软件app
  • 网页制作和网站开发站长工具外链查询