Skip to content

Commit

Permalink
feat: add server side (#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
L2ncE authored Sep 13, 2023
1 parent c0beb47 commit 5d1552b
Show file tree
Hide file tree
Showing 7 changed files with 980 additions and 18 deletions.
17 changes: 13 additions & 4 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/server"
)

// dubbo role type constant
Expand Down Expand Up @@ -110,10 +111,11 @@ type URL struct {
paramsLock sync.RWMutex
params url.Values

Path string // like /com.ikurento.dubbo.UserProvider
Username string
Password string
Methods []string
Path string // like /com.ikurento.dubbo.UserProvider
Username string
Password string
Methods []string
MethodInfo []server.MethodInfo
// special for registry
SubURL *URL
}
Expand Down Expand Up @@ -218,6 +220,13 @@ func WithToken(token string) Option {
}
}

// WithMethodInfos sets methodInfos for URL
func WithMethodInfos(methodInfos []server.MethodInfo) Option {
return func(url *URL) {
url.MethodInfo = methodInfos
}
}

// NewURLWithOptions will create a new URL with options
func NewURLWithOptions(opts ...Option) *URL {
newURL := &URL{}
Expand Down
207 changes: 207 additions & 0 deletions global/service_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
package global

// ServiceConfig is the configuration of the service provider
type ServiceConfig struct {
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
ProtocolIDs []string `yaml:"protocol-ids" json:"protocol-ids,omitempty" property:"protocol-ids"` // multi protocolIDs support, split by ','
Interface string `yaml:"interface" json:"interface,omitempty" property:"interface"`
RegistryIDs []string `yaml:"registry-ids" json:"registry-ids,omitempty" property:"registry-ids"`
Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty" property:"cluster"`
Loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"`
Group string `yaml:"group" json:"group,omitempty" property:"group"`
Version string `yaml:"version" json:"version,omitempty" property:"version" `
Methods []*MethodConfig `yaml:"methods" json:"methods,omitempty" property:"methods"`
Warmup string `yaml:"warmup" json:"warmup,omitempty" property:"warmup"`
Retries string `yaml:"retries" json:"retries,omitempty" property:"retries"`
Serialization string `yaml:"serialization" json:"serialization" property:"serialization"`
Params map[string]string `yaml:"params" json:"params,omitempty" property:"params"`
Token string `yaml:"token" json:"token,omitempty" property:"token"`
AccessLog string `yaml:"accesslog" json:"accesslog,omitempty" property:"accesslog"`
TpsLimiter string `yaml:"tps.limiter" json:"tps.limiter,omitempty" property:"tps.limiter"`
TpsLimitInterval string `yaml:"tps.limit.interval" json:"tps.limit.interval,omitempty" property:"tps.limit.interval"`
TpsLimitRate string `yaml:"tps.limit.rate" json:"tps.limit.rate,omitempty" property:"tps.limit.rate"`
TpsLimitStrategy string `yaml:"tps.limit.strategy" json:"tps.limit.strategy,omitempty" property:"tps.limit.strategy"`
TpsLimitRejectedHandler string `yaml:"tps.limit.rejected.handler" json:"tps.limit.rejected.handler,omitempty" property:"tps.limit.rejected.handler"`
ExecuteLimit string `yaml:"execute.limit" json:"execute.limit,omitempty" property:"execute.limit"`
ExecuteLimitRejectedHandler string `yaml:"execute.limit.rejected.handler" json:"execute.limit.rejected.handler,omitempty" property:"execute.limit.rejected.handler"`
Auth string `yaml:"auth" json:"auth,omitempty" property:"auth"`
NotRegister bool `yaml:"not_register" json:"not_register,omitempty" property:"not_register"`
ParamSign string `yaml:"param.sign" json:"param.sign,omitempty" property:"param.sign"`
Tag string `yaml:"tag" json:"tag,omitempty" property:"tag"`
TracingKey string `yaml:"tracing-key" json:"tracing-key,omitempty" propertiy:"tracing-key"`
}

type ServiceOption func(*ServiceConfig)

func DefaultServiceConfig() *ServiceConfig {
return &ServiceConfig{
Methods: make([]*MethodConfig, 0, 8),
Params: make(map[string]string, 8),
}
}

func WithService_Filter(filter string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Filter = filter
}
}

func WithService_ProtocolIDs(protocolIDs []string) ServiceOption {
return func(cfg *ServiceConfig) {
if len(protocolIDs) <= 0 {
cfg.ProtocolIDs = protocolIDs
}
}
}

func WithService_Interface(name string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Interface = name
}
}

func WithService_RegistryIDs(registryIDs []string) ServiceOption {
return func(cfg *ServiceConfig) {
if len(registryIDs) <= 0 {
cfg.RegistryIDs = registryIDs
}
}
}

func WithService_Cluster(cluster string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Cluster = cluster
}
}

func WithService_LoadBalance(loadBalance string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Loadbalance = loadBalance
}
}

func WithService_Group(group string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Group = group
}
}

func WithService_Version(version string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Version = version
}
}

func WithService_Methods(methods []*MethodConfig) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Methods = methods
}
}

func WithService_WarmUp(warmUp string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Warmup = warmUp
}
}

func WithService_Retries(retries string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Retries = retries
}
}

func WithService_Serialization(serialization string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Serialization = serialization
}
}

func WithService_Params(params map[string]string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Params = params
}
}

func WithService_Token(token string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Token = token
}
}

func WithService_AccessLog(accessLog string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.AccessLog = accessLog
}
}

func WithService_TpsLimiter(tpsLimiter string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.TpsLimiter = tpsLimiter
}
}

func WithService_TpsLimitInterval(tpsLimitInterval string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.TpsLimitInterval = tpsLimitInterval
}
}

func WithService_TpsLimitRate(tpsLimitRate string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.TpsLimitRate = tpsLimitRate
}
}

func WithService_TpsLimitStrategy(tpsLimitStrategy string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.TpsLimitStrategy = tpsLimitStrategy
}
}

func WithService_TpsLimitRejectedHandler(tpsLimitRejectedHandler string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.TpsLimitRejectedHandler = tpsLimitRejectedHandler
}
}

func WithService_ExecuteLimit(executeLimit string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.ExecuteLimit = executeLimit
}
}

func WithService_ExecuteLimitRejectedHandler(executeLimitRejectedHandler string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.ExecuteLimitRejectedHandler = executeLimitRejectedHandler
}
}

func WithService_Auth(auth string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Auth = auth
}
}

func WithService_NotRegister(notRegister bool) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.NotRegister = notRegister
}
}

func WithService_ParamSign(paramSign string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.ParamSign = paramSign
}
}

func WithService_Tag(tag string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.Tag = tag
}
}

func WithService_TracingKey(tracingKey string) ServiceOption {
return func(cfg *ServiceConfig) {
cfg.TracingKey = tracingKey
}
}
5 changes: 4 additions & 1 deletion protocol/triple/triple.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func (tp *TripleProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
url := invoker.GetURL()
serviceKey := url.ServiceKey()
// todo: retrieve this info from url
info := &server.ServiceInfo{}
info := &server.ServiceInfo{
InterfaceName: url.Path,
Methods: url.MethodInfo,
}
exporter := NewTripleExporter(serviceKey, invoker, tp.ExporterMap())
tp.SetExporterMap(serviceKey, exporter)
logger.Infof("[TRIPLE Protocol] Export service: %s", url.String())
Expand Down
Loading

0 comments on commit 5d1552b

Please sign in to comment.