Kitex 支持自定義注冊(cè)模塊,使用者可自行擴(kuò)展集成其他注冊(cè)中心,該擴(kuò)展定義在 pkg/registry 下。
// Registry is extension interface of service registry.
type Registry interface {
Register(info *Info) error
Deregister(info *Info) error
}
// Info is used for registry.
// The fields are just suggested, which is used depends on design.
type Info struct {
// ServiceName will be set in kitex by default
ServiceName string
// Addr will be set in kitex by default
Addr net.Addr
// PayloadCodec will be set in kitex by default, like thrift, protobuf
PayloadCodec string
Weight int
StartTime time.Time
WarmUp time.Duration
// extend other infos with Tags.
Tags map[string]string
}
通過(guò) option 指定自己的注冊(cè)模塊和自定義的注冊(cè)信息。注意注冊(cè)需要服務(wù)信息,服務(wù)信息也是通過(guò) option 指定。
option: ?WithServerBasicInfo
?
ebi := &rpcinfo.EndpointBasicInfo{
ServiceName: 'yourServiceName',
Tags: make(map[string]string),
}
ebi.Tags[idc] = "xxx"
svr := xxxservice.NewServer(handler, server.WithServerBasicInfo(ebi))
WithRegistry
?svr := xxxservice.NewServer(handler, server.WithServerBasicInfo(ebi), server.WithRegistry(yourRegistry))
WithRegistryInfo
?svr := xxxservice.NewServer(handler, server.WithRegistry(yourRegistry), server.WithRegistryInfo(yourRegistryInfo))
更多建議: