Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
22202f87
Commit
22202f87
authored
5 years ago
by
fangyincheng
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop-2.6.0' of
https://github.com/dubbogo/dubbo-go
into develop-2.6.0
parents
45ff270a
ebedbf2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config/config_url.go
+24
-3
24 additions, 3 deletions
config/config_url.go
config/support/reference_config.go
+47
-19
47 additions, 19 deletions
config/support/reference_config.go
config/support/service_config.go
+25
-15
25 additions, 15 deletions
config/support/service_config.go
with
96 additions
and
37 deletions
config/config_url.go
+
24
−
3
View file @
22202f87
...
...
@@ -68,11 +68,32 @@ func WithParams(params url.Values) option {
}
}
func
NewURLWithOptions
(
service
string
,
protocol
string
,
ip
string
,
port
string
,
path
string
,
opts
...
option
)
*
URL
{
func
WithProtocol
(
proto
string
)
option
{
return
func
(
url
*
URL
)
{
url
.
Protocol
=
proto
}
}
func
WithIp
(
ip
string
)
option
{
return
func
(
url
*
URL
)
{
url
.
Ip
=
ip
}
}
func
WithPort
(
port
string
)
option
{
return
func
(
url
*
URL
)
{
url
.
Port
=
port
}
}
func
WithPath
(
path
string
)
option
{
return
func
(
url
*
URL
)
{
url
.
Path
=
path
}
}
func
NewURLWithOptions
(
service
string
,
opts
...
option
)
*
URL
{
url
:=
&
URL
{
baseUrl
:
baseUrl
{
Protocol
:
protocol
,
Ip
:
ip
,
Port
:
port
},
Service
:
service
,
Path
:
path
,
}
for
_
,
opt
:=
range
opts
{
opt
(
url
)
...
...
This diff is collapsed.
Click to expand it.
config/support/reference_config.go
+
47
−
19
View file @
22202f87
...
...
@@ -2,36 +2,39 @@ package support
import
(
"context"
"github.com/dubbo/dubbo-go/common/constant"
"github.com/dubbo/dubbo-go/config"
"net/url"
"strconv"
"time"
)
import
(
"github.com/dubbo/dubbo-go/common/extension"
"github.com/dubbo/dubbo-go/common/proxy"
"github.com/dubbo/dubbo-go/config"
"github.com/dubbo/dubbo-go/protocol"
)
type
ReferenceConfig
struct
{
context
context
.
Context
pxy
*
proxy
.
Proxy
Interface
string
`required:"true" yaml:"interface" json:"interface,omitempty"`
Registries
[]
ConfigRegistry
`required:"true" yaml:"registries" json:"registries,omitempty"`
Cluster
string
`default:"failover" yaml:"cluster" json:"cluster,omitempty"`
Methods
[]
method
`yaml:"methods" json:"methods,omitempty"`
URLs
[]
config
.
URL
`yaml:"-"`
Async
bool
`yaml:"async" json:"async,omitempty"`
invoker
protocol
.
Invoker
context
context
.
Context
pxy
*
proxy
.
Proxy
Interface
string
`required:"true" yaml:"interface" json:"interface,omitempty"`
Registries
[]
ConfigRegistry
`required:"true" yaml:"registries" json:"registries,omitempty"`
Cluster
string
`default:"failover" yaml:"cluster" json:"cluster,omitempty"`
Loadbalance
string
`default:"random" yaml:"loadbalance" json:"loadbalance,omitempty"`
retries
int64
`yaml:"retries" json:"retries,omitempty"`
Methods
[]
struct
{
name
string
`yaml:"name" json:"name,omitempty"`
retries
int64
`yaml:"retries" json:"retries,omitempty"`
loadbalance
string
`yaml:"loadbalance" json:"loadbalance,omitempty"`
}
`yaml:"methods" json:"methods,omitempty"`
Async
bool
`yaml:"async" json:"async,omitempty"`
invoker
protocol
.
Invoker
}
type
ConfigRegistry
struct
{
string
}
type
method
struct
{
name
string
`yaml:"name" json:"name,omitempty"`
retries
int64
`yaml:"retries" json:"retries,omitempty"`
loadbalance
string
`yaml:"loadbalance" json:"loadbalance,omitempty"`
}
func
NewReferenceConfig
(
ctx
context
.
Context
)
*
ReferenceConfig
{
return
&
ReferenceConfig
{
context
:
ctx
}
}
...
...
@@ -40,10 +43,16 @@ func (refconfig *ReferenceConfig) Refer() {
//首先是user specified URL, could be peer-to-peer address, or register center's address.
//其次是assemble URL from register center's configuration模式
urls
:=
loadRegistries
(
refconfig
.
Registries
,
consumerConfig
.
Registries
)
regUrls
:=
loadRegistries
(
refconfig
.
Registries
,
consumerConfig
.
Registries
)
url
:=
config
.
NewURLWithOptions
(
refconfig
.
Interface
,
config
.
WithParams
(
refconfig
.
getUrlMap
()))
if
len
(
urls
)
==
1
{
refconfig
.
invoker
=
extension
.
GetProtocolExtension
(
"registry"
)
.
Refer
(
urls
[
0
])
//set url to regUrls
for
_
,
regUrl
:=
range
regUrls
{
regUrl
.
URL
=
*
url
}
if
len
(
regUrls
)
==
1
{
refconfig
.
invoker
=
extension
.
GetProtocolExtension
(
"registry"
)
.
Refer
(
regUrls
[
0
])
}
else
{
//TODO:multi registries ,just wrap multi registry as registry cluster invoker including cluster invoker
...
...
@@ -57,3 +66,22 @@ func (refconfig *ReferenceConfig) Refer() {
func
(
refconfig
*
ReferenceConfig
)
Implement
(
v
config
.
RPCService
)
error
{
return
refconfig
.
pxy
.
Implement
(
v
)
}
func
(
refconfig
*
ReferenceConfig
)
getUrlMap
()
url
.
Values
{
urlMap
:=
url
.
Values
{}
urlMap
.
Set
(
constant
.
TIMESTAMP_KEY
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
))
urlMap
.
Set
(
constant
.
CLUSTER_KEY
,
refconfig
.
Cluster
)
urlMap
.
Set
(
constant
.
LOADBALANCE_KEY
,
refconfig
.
Loadbalance
)
urlMap
.
Set
(
constant
.
RETRIES_KEY
,
strconv
.
FormatInt
(
refconfig
.
retries
,
10
))
//getty invoke async or sync
urlMap
.
Set
(
constant
.
ASYNC_KEY
,
strconv
.
FormatBool
(
refconfig
.
Async
))
for
_
,
v
:=
range
refconfig
.
Methods
{
urlMap
.
Set
(
"methods."
+
v
.
name
+
"."
+
constant
.
LOADBALANCE_KEY
,
v
.
loadbalance
)
urlMap
.
Set
(
"methods."
+
v
.
name
+
"."
+
constant
.
RETRIES_KEY
,
strconv
.
FormatInt
(
v
.
retries
,
10
))
}
return
urlMap
}
This diff is collapsed.
Click to expand it.
config/support/service_config.go
+
25
−
15
View file @
22202f87
...
...
@@ -25,13 +25,16 @@ type ServiceConfig struct {
Registries
[]
ConfigRegistry
`required:"true" yaml:"registries" json:"registries,omitempty"`
Cluster
string
`default:"failover" yaml:"cluster" json:"cluster,omitempty"`
Loadbalance
string
`default:"random" yaml:"loadbalance" json:"loadbalance,omitempty"`
Methods
[]
method
`yaml:"methods" json:"methods,omitempty"`
warmup
string
`yaml:"warmup" json:"warmup,omitempty"`
retries
int64
`yaml:"retries" json:"retries,omitempty"`
unexported
*
atomic
.
Bool
exported
*
atomic
.
Bool
URLs
[]
config
.
URL
Methods
[]
struct
{
name
string
`yaml:"name" json:"name,omitempty"`
retries
int64
`yaml:"retries" json:"retries,omitempty"`
loadbalance
string
`yaml:"loadbalance" json:"loadbalance,omitempty"`
weight
int64
`yaml:"weight" json:"weight,omitempty"`
}
`yaml:"methods" json:"methods,omitempty"`
warmup
string
`yaml:"warmup" json:"warmup,omitempty"`
retries
int64
`yaml:"retries" json:"retries,omitempty"`
unexported
*
atomic
.
Bool
exported
*
atomic
.
Bool
rpcService
config
.
RPCService
exporters
[]
protocol
.
Exporter
}
...
...
@@ -59,7 +62,7 @@ func (srvconfig *ServiceConfig) Export() error {
}
regUrls
:=
loadRegistries
(
srvconfig
.
Registries
,
providerConfig
.
Registries
)
urlMap
:=
getUrlMap
(
srvconfig
)
urlMap
:=
srvconfig
.
getUrlMap
()
for
_
,
proto
:=
range
loadProtocol
(
srvconfig
.
Protocol
,
providerConfig
.
Protocols
)
{
//registry the service reflect
...
...
@@ -73,7 +76,13 @@ func (srvconfig *ServiceConfig) Export() error {
if
contextPath
==
""
{
contextPath
=
providerConfig
.
Path
}
url
:=
config
.
NewURLWithOptions
(
srvconfig
.
Interface
,
proto
.
name
,
proto
.
ip
,
proto
.
port
,
contextPath
,
config
.
WithParams
(
urlMap
))
url
:=
config
.
NewURLWithOptions
(
srvconfig
.
Interface
,
config
.
WithProtocol
(
proto
.
name
),
config
.
WithIp
(
proto
.
ip
),
config
.
WithPort
(
proto
.
port
),
config
.
WithPath
(
contextPath
),
config
.
WithParams
(
urlMap
))
for
_
,
regUrl
:=
range
regUrls
{
regUrl
.
URL
=
*
url
invoker
:=
protocol
.
NewBaseInvoker
(
regUrl
)
...
...
@@ -89,18 +98,19 @@ func (srvconfig *ServiceConfig) Implement(s config.RPCService) {
srvconfig
.
rpcService
=
s
}
func
getUrlMap
(
config
*
ServiceConfig
)
url
.
Values
{
func
(
srv
config
*
ServiceConfig
)
getUrlMap
()
url
.
Values
{
urlMap
:=
url
.
Values
{}
urlMap
.
Set
(
constant
.
TIMESTAMP_KEY
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
))
urlMap
.
Set
(
constant
.
CLUSTER_KEY
,
config
.
Cluster
)
urlMap
.
Set
(
constant
.
LOADBALANCE_KEY
,
config
.
Loadbalance
)
urlMap
.
Set
(
constant
.
WARMUP_KEY
,
config
.
warmup
)
urlMap
.
Set
(
constant
.
RETRIES_KEY
,
strconv
.
FormatInt
(
config
.
retries
,
10
))
urlMap
.
Set
(
constant
.
CLUSTER_KEY
,
srv
config
.
Cluster
)
urlMap
.
Set
(
constant
.
LOADBALANCE_KEY
,
srv
config
.
Loadbalance
)
urlMap
.
Set
(
constant
.
WARMUP_KEY
,
srv
config
.
warmup
)
urlMap
.
Set
(
constant
.
RETRIES_KEY
,
strconv
.
FormatInt
(
srv
config
.
retries
,
10
))
for
_
,
v
:=
range
config
.
Methods
{
for
_
,
v
:=
range
srv
config
.
Methods
{
urlMap
.
Set
(
"methods."
+
v
.
name
+
"."
+
constant
.
LOADBALANCE_KEY
,
v
.
loadbalance
)
urlMap
.
Set
(
"methods."
+
v
.
name
+
"."
+
constant
.
RETRIES_KEY
,
strconv
.
FormatInt
(
v
.
retries
,
10
))
urlMap
.
Set
(
"methods."
+
v
.
name
+
"."
+
constant
.
WEIGHT_KEY
,
strconv
.
FormatInt
(
v
.
weight
,
10
))
}
return
urlMap
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment