You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "DMwangnima (via GitHub)" <gi...@apache.org> on 2023/09/22 15:58:46 UTC
[GitHub] [dubbo-go] DMwangnima opened a new issue, #2433: Client and Server configuration APIs proposal
DMwangnima opened a new issue, #2433:
URL: https://github.com/apache/dubbo-go/issues/2433
<!-- Please only use this template for submitting enhancement requests -->
**What would you like to be added**:
Client configuration APIs:
```go
func WithCheck(check bool) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Check = &check
}
}
// For direct connection scenario
func WithURL(url string) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.URL = url
}
}
// Filter would be changed like Cluster and LoadBalance
func WithFilter(filter string) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Filter = filter
}
}
// RegistryIDs should be considered
func WithRegistryIDs(registryIDs []string) ClientOption {
return func(opts *ClientOptions) {
if len(registryIDs) > 0 {
opts.Reference.RegistryIDs = registryIDs
}
}
}
// ========== Cluster Strategy ==========
// Previous API is WithCluster(string), users would be confused about what Cluster Strategies we have provided
// and how to specify them.
// Solution is enumerating these strategies.
func WithClusterAvailable() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyAvailable
}
}
func WithClusterBroadcast() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyBroadcast
}
}
func WithClusterFailBack() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyFailback
}
}
func WithClusterFailFast() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyFailfast
}
}
func WithClusterFailOver() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyFailover
}
}
func WithClusterFailSafe() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyFailsafe
}
}
func WithClusterForking() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyForking
}
}
func WithClusterZoneAware() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyZoneAware
}
}
func WithClusterAdaptiveService() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Cluster = constant.ClusterKeyAdaptiveService
}
}
// ========== LoadBalance Strategy ==========
// It is same as Cluster configuration
func WithLoadBalanceConsistentHashing() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Loadbalance = constant.LoadBalanceKeyConsistentHashing
}
}
func WithLoadBalanceLeastActive() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Loadbalance = constant.LoadBalanceKeyLeastActive
}
}
func WithLoadBalanceRandom() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Loadbalance = constant.LoadBalanceKeyRandom
}
}
func WithLoadBalanceRoundRobin() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Loadbalance = constant.LoadBalanceKeyRoundRobin
}
}
func WithLoadBalanceP2C() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Loadbalance = constant.LoadBalanceKeyP2C
}
}
func WithLoadBalanceXDSRingHash() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Loadbalance = constant.LoadBalanceKeyLeastActive
}
}
func WithRetries(retries int) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Retries = strconv.Itoa(retries)
}
}
func WithGroup(group string) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Group = group
}
}
func WithVersion(version string) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Version = version
}
}
// Using Protobuf by default. If users want to adopt JSON serialization, use this API.
func WithJSON() ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Serialization = constant.JSONSerialization
}
}
func WithProvidedBy(providedBy string) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.ProvidedBy = providedBy
}
}
func WithParams(params map[string]string) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Params = params
}
}
func WithSticky(sticky bool) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.Sticky = sticky
}
}
func WithRequestTimeout(timeout time.Duration) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.RequestTimeout = timeout.String()
}
}
func WithForce(force bool) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.ForceTag = force
}
}
func WithTracingKey(tracingKey string) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.TracingKey = tracingKey
}
}
func WithMeshProviderPort(port int) ClientOption {
return func(opts *ClientOptions) {
opts.Reference.MeshProviderPort = port
}
}
```
Server configuration APIs:
```go
// Need to change Filter Option like Cluster and LoadBalance
func WithServer_Filter(filter string) ServerOption {
return func(opts *ServerOptions) {
opts.Provider.Filter = filter
}
}
// Need to think about a more ideal configuration style
func WithServer_RegistryIDs(registryIDs []string) ServerOption {
return func(opts *ServerOptions) {
opts.Provider.RegistryIDs = registryIDs
}
}
// Need to think about a more ideal configuration style
func WithServer_ProtocolIDs(protocolIDs []string) ServerOption {
return func(opts *ServerOptions) {
opts.Provider.ProtocolIDs = protocolIDs
}
}
func WithServer_TracingKey(tracingKey string) ServerOption {
return func(opts *ServerOptions) {
opts.Provider.TracingKey = tracingKey
}
}
// This configuration would be used by filter/hystrix.
// Think about a more ideal way to configure.
func WithServer_FilterConf(conf interface{}) ServerOption {
return func(opts *ServerOptions) {
opts.Provider.FilterConf = conf
}
}
func WithServer_AdaptiveService() ServerOption {
return func(opts *ServerOptions) {
opts.Provider.AdaptiveService = true
}
}
func WithServer_AdaptiveServiceVerbose() ServerOption {
return func(opts *ServerOptions) {
opts.Provider.AdaptiveServiceVerbose = true
}
}
// Think about a more ideal configuration style
func WithRegistryIDs(registryIDs []string) ServiceOption {
return func(cfg *ServiceOptions) {
if len(registryIDs) <= 0 {
cfg.Service.RegistryIDs = registryIDs
}
}
}
// Change Filter Option like Cluster and LoadBalance
func WithFilter(filter string) ServiceOption {
return func(cfg *ServiceOptions) {
cfg.Service.Filter = filter
}
}
// Think about a more ideal configuration style
func WithProtocolIDs(protocolIDs []string) ServiceOption {
return func(cfg *ServiceOptions) {
if len(protocolIDs) <= 0 {
cfg.Service.ProtocolIDs = protocolIDs
}
}
}
func WithTracingKey(tracingKey string) ServiceOption {
return func(cfg *ServiceOptions) {
cfg.Service.TracingKey = tracingKey
}
}
// ========== LoadBalance Strategy ==========
func WithLoadBalanceConsistentHashing() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Loadbalance = constant.LoadBalanceKeyConsistentHashing
}
}
func WithLoadBalanceLeastActive() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Loadbalance = constant.LoadBalanceKeyLeastActive
}
}
func WithLoadBalanceRandom() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Loadbalance = constant.LoadBalanceKeyRandom
}
}
func WithLoadBalanceRoundRobin() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Loadbalance = constant.LoadBalanceKeyRoundRobin
}
}
func WithLoadBalanceP2C() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Loadbalance = constant.LoadBalanceKeyP2C
}
}
func WithLoadBalanceXDSRingHash() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Loadbalance = constant.LoadBalanceKeyLeastActive
}
}
// warmUp is in seconds
func WithWarmUp(warmUp time.Duration) ServiceOption {
return func(opts *ServiceOptions) {
warmUpSec := int(warmUp / time.Second)
opts.Service.Warmup = strconv.Itoa(warmUpSec)
}
}
// ========== Cluster Strategy ==========
func WithClusterAvailable() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyAvailable
}
}
func WithClusterBroadcast() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyBroadcast
}
}
func WithClusterFailBack() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyFailback
}
}
func WithClusterFailFast() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyFailfast
}
}
func WithClusterFailOver() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyFailover
}
}
func WithClusterFailSafe() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyFailsafe
}
}
func WithClusterForking() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyForking
}
}
func WithClusterZoneAware() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyZoneAware
}
}
func WithClusterAdaptiveService() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Cluster = constant.ClusterKeyAdaptiveService
}
}
func WithGroup(group string) ServiceOption {
return func(cfg *ServiceOptions) {
cfg.Service.Group = group
}
}
func WithVersion(version string) ServiceOption {
return func(cfg *ServiceOptions) {
cfg.Service.Version = version
}
}
func WithJSON() ServiceOption {
return func(opts *ServiceOptions) {
opts.Service.Serialization = constant.JSONSerialization
}
}
// For direct connection scenario. If users do not configure any Registry, this option
// would be set to true automatically.
func WithNotRegister() ServiceOption {
return func(cfg *ServiceOptions) {
cfg.Service.NotRegister = true
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [I] Client and Server configuration APIs proposal [dubbo-go]
Posted by "DMwangnima (via GitHub)" <gi...@apache.org>.
DMwangnima closed issue #2433: Client and Server configuration APIs proposal
URL: https://github.com/apache/dubbo-go/issues/2433
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go] DMwangnima commented on issue #2433: Client and Server configuration APIs proposal
Posted by "DMwangnima (via GitHub)" <gi...@apache.org>.
DMwangnima commented on issue #2433:
URL: https://github.com/apache/dubbo-go/issues/2433#issuecomment-1731671492
Sum up:
1. Using default values as much as possible to reduce configurations. e.g. Using ```WithNotRegister()`` instead of ```WithNotRegister(true)``` if users do not hope to register. Dubbo-go would register service by default.
2. Enumerating concrete configuration options like ```WithClusterAvailable``` for configurations that would not change frequently. Users could know exact functionalities that we have provided easily.
3. RegistryIDs and ProtocolIDs should be considered well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [I] Client and Server configuration APIs proposal [dubbo-go]
Posted by "chickenlj (via GitHub)" <gi...@apache.org>.
chickenlj commented on issue #2433:
URL: https://github.com/apache/dubbo-go/issues/2433#issuecomment-1757255608
> * Using default values as much as possible to reduce configurations. e.g. Using `` WithNotRegister()`` instead of ``WithNotRegister(true)``` if users do not hope to register. Dubbo-go would register service by default.
> * Enumerating concrete configuration options like `WithClusterAvailable` for configurations that would not change frequently. Users could know exact functionalities that we have provided easily.
I personally totally agree with this kind of API design. Much easier for users to understand what will happend just by looking at the name of the method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org