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
d19a14b0
Commit
d19a14b0
authored
5 years ago
by
pantianying
Browse files
Options
Downloads
Patches
Plain Diff
改成和java一样的使用方式
parent
cdb32e1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/generic_reference_config.go
+7
-47
7 additions, 47 deletions
config/generic_reference_config.go
examples/dubbo/go-client/app/client.go
+4
-4
4 additions, 4 deletions
examples/dubbo/go-client/app/client.go
with
11 additions
and
51 deletions
config/generic_reference_config.go
+
7
−
47
View file @
d19a14b0
package
config
import
(
"context"
"errors"
)
const
GenericReferKey
=
"GenericReferKey"
type
GenericService
struct
{
Invoke
func
(
req
[]
interface
{})
(
interface
{},
error
)
`dubbo:"$invoke"`
referenceStr
string
}
func
NewGenericService
(
referenceStr
string
)
*
GenericService
{
return
&
GenericService
{
referenceStr
:
GenericReferKey
}
return
&
GenericService
{
referenceStr
:
referenceStr
}
}
func
(
u
*
GenericService
)
Reference
()
string
{
return
u
.
referenceStr
}
type
GenericConsumerConfig
struct
{
ID
string
Protocol
string
Registry
string
Version
string
Group
string
InterfaceName
string
Cluster
string
Retries
int64
ref
*
ReferenceConfig
genericService
*
GenericService
}
func
(
gConfig
*
GenericConsumerConfig
)
Load
()
(
err
error
)
{
gr
:=
NewReferenceConfig
(
context
.
TODO
())
func
(
refconfig
*
ReferenceConfig
)
Load
(
id
string
)
{
//gr.Filter = "genericConsumer" //todo: add genericConsumer filter
gr
.
Registry
=
gConfig
.
Registry
gr
.
Protocol
=
gConfig
.
Protocol
gr
.
Version
=
gConfig
.
Version
gr
.
Group
=
gConfig
.
Group
gr
.
InterfaceName
=
gConfig
.
InterfaceName
gr
.
Cluster
=
gConfig
.
Cluster
gr
.
Methods
=
append
(
gr
.
Methods
,
&
MethodConfig
{
Name
:
"$invoke"
,
Retries
:
gConfig
.
Retries
})
gConfig
.
ref
=
gr
gConfig
.
genericService
=
NewGenericService
(
gConfig
.
ID
)
SetConsumerService
(
gConfig
.
genericService
)
rpcService
:=
GetConsumerService
(
GenericReferKey
)
if
rpcService
==
nil
{
err
=
errors
.
New
(
"get rpcService err,GenericReferKey not Set "
)
return
}
gConfig
.
ref
.
id
=
gConfig
.
ID
gConfig
.
ref
.
Refer
()
gConfig
.
ref
.
Implement
(
rpcService
)
genericService
:=
NewGenericService
(
refconfig
.
id
)
SetConsumerService
(
genericService
)
refconfig
.
id
=
id
refconfig
.
Refer
()
refconfig
.
Implement
(
genericService
)
return
}
func
(
gConfig
*
GenericConsumerConfig
)
GetGenericService
()
*
GenericService
{
return
gConfig
.
genericService
}
This diff is collapsed.
Click to expand it.
examples/dubbo/go-client/app/client.go
+
4
−
4
View file @
d19a14b0
...
...
@@ -290,18 +290,18 @@ func test2() {
println
(
"error: %v"
,
err
)
}
func
test3
()
{
var
genericConfig
=
config
.
GenericConsumerConfig
{
ID
:
"UserProviderGer"
,
//GetService的唯一标识不可缺少
var
appName
=
"UserProviderGer"
var
referenceConfig
=
config
.
ReferenceConfig
{
InterfaceName
:
"com.ikurento.user.UserProvider"
,
Cluster
:
"failover"
,
Registry
:
"hangzhouzk"
,
Protocol
:
dubbo
.
DUBBO
,
}
generic
Config
.
Load
(
)
reference
Config
.
Load
(
appName
)
//appName是GetService的唯一标识不可缺少
time
.
Sleep
(
3
*
time
.
Second
)
println
(
"
\n\n\n
start to generic invoke"
)
resp
,
err
:=
generic
Config
.
GetGenericService
(
)
.
Invoke
([]
interface
{}{
"GetUser"
,
[]
string
{
"java.lang.String"
},
[]
hessian
.
Object
{
"A003"
}})
resp
,
err
:=
reference
Config
.
Get
RPCService
()
.
(
*
config
.
GenericService
)
.
Invoke
([]
interface
{}{
"GetUser"
,
[]
string
{
"java.lang.String"
},
[]
hessian
.
Object
{
"A003"
}})
if
err
!=
nil
{
panic
(
err
)
}
...
...
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