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
97512662
Commit
97512662
authored
5 years ago
by
pantianying
Browse files
Options
Downloads
Patches
Plain Diff
add go to java generic
parent
47c4d200
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/generic_reference_config.go
+63
-0
63 additions, 0 deletions
config/generic_reference_config.go
config/reference_config.go
+2
-3
2 additions, 3 deletions
config/reference_config.go
examples/dubbo/go-client/app/client.go
+32
-17
32 additions, 17 deletions
examples/dubbo/go-client/app/client.go
with
97 additions
and
20 deletions
config/generic_reference_config.go
0 → 100644
+
63
−
0
View file @
97512662
package
config
import
(
"context"
"github.com/apache/dubbo-go/common/logger"
)
type
GenericService
struct
{
Invoke
func
(
req
[]
interface
{})
(
interface
{},
error
)
`dubbo:"$invoke"`
referenceStr
string
}
func
NewGenericService
(
reference
string
)
*
GenericService
{
return
&
GenericService
{
referenceStr
:
reference
}
}
func
(
u
*
GenericService
)
Reference
()
string
{
return
u
.
referenceStr
}
type
GenericConsumerConfig
struct
{
Protocol
string
Registry
string
Version
string
Group
string
InterfaceName
string
Cluster
string
Retries
int64
ref
*
ReferenceConfig
genericService
*
GenericService
}
func
(
gConfig
*
GenericConsumerConfig
)
LoadGenericReferenceConfig
(
key
string
)
{
gConfig
.
genericService
=
NewGenericService
(
key
)
SetConsumerService
(
gConfig
.
genericService
)
gConfig
.
NewGenericReferenceConfig
(
key
)
rpcService
:=
GetConsumerService
(
key
)
if
rpcService
==
nil
{
logger
.
Warnf
(
"%s is not exsist!"
,
key
)
return
}
gConfig
.
ref
.
id
=
key
gConfig
.
ref
.
Refer
()
gConfig
.
ref
.
Implement
(
rpcService
)
}
func
(
gConfig
*
GenericConsumerConfig
)
GetService
()
*
GenericService
{
return
gConfig
.
genericService
}
func
(
gConfig
*
GenericConsumerConfig
)
NewGenericReferenceConfig
(
id
string
)
{
gr
:=
NewReferenceConfig
(
id
,
context
.
TODO
())
//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
}
This diff is collapsed.
Click to expand it.
config/reference_config.go
+
2
−
3
View file @
97512662
...
...
@@ -61,8 +61,8 @@ func (c *ReferenceConfig) Prefix() string {
return
constant
.
ReferenceConfigPrefix
+
c
.
InterfaceName
+
"."
}
func
NewReferenceConfig
(
ctx
context
.
Context
)
*
ReferenceConfig
{
return
&
ReferenceConfig
{
context
:
ctx
}
func
NewReferenceConfig
(
id
string
,
ctx
context
.
Context
)
*
ReferenceConfig
{
return
&
ReferenceConfig
{
id
:
id
,
context
:
ctx
}
}
func
(
refconfig
*
ReferenceConfig
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
...
...
@@ -109,7 +109,6 @@ func (refconfig *ReferenceConfig) Refer() {
regUrl
.
SubURL
=
url
}
}
if
len
(
refconfig
.
urls
)
==
1
{
refconfig
.
invoker
=
extension
.
GetProtocol
(
refconfig
.
urls
[
0
]
.
Protocol
)
.
Refer
(
*
refconfig
.
urls
[
0
])
}
else
{
...
...
This diff is collapsed.
Click to expand it.
examples/dubbo/go-client/app/client.go
+
32
−
17
View file @
97512662
...
...
@@ -20,16 +20,14 @@ package main
import
(
"context"
"fmt"
"github.com/apache/dubbo-go/protocol/dubbo"
hessian
"github.com/dubbogo/hessian2"
"os"
"os/signal"
"syscall"
"time"
)
import
(
"github.com/dubbogo/hessian2"
)
import
(
"github.com/apache/dubbo-go/common/logger"
_
"github.com/apache/dubbo-go/common/proxy/proxy_factory"
...
...
@@ -53,19 +51,20 @@ var (
// export APP_LOG_CONF_FILE="xxx"
func
main
()
{
hessian
.
RegisterJavaEnum
(
Gender
(
MAN
))
hessian
.
RegisterJavaEnum
(
Gender
(
WOMAN
))
hessian
.
RegisterPOJO
(
&
User
{})
config
.
Load
()
println
(
"
\n\n
test"
)
test
()
println
(
"
\n\n
test1"
)
test1
()
println
(
"
\n\n
test2"
)
test2
()
//hessian.RegisterJavaEnum(Gender(MAN))
//hessian.RegisterJavaEnum(Gender(WOMAN))
//hessian.RegisterPOJO(&User{})
//
//config.Load()
//println("\n\ntest")
//test()
//println("\n\ntest1")
//test1()
//println("\n\ntest2")
//test2()
//println("\n\ngeneric")
test3
()
initSignal
()
}
...
...
@@ -288,3 +287,19 @@ func test2() {
}
println
(
"error: %v"
,
err
)
}
func
test3
()
{
println
(
"
\n\n\n
start to generic invoke"
)
var
genericConfig
config
.
GenericConsumerConfig
genericConfig
.
InterfaceName
=
"com.ikurento.user.UserProvider"
genericConfig
.
Cluster
=
"failover"
genericConfig
.
Registry
=
"hangzhouzk"
genericConfig
.
Protocol
=
dubbo
.
DUBBO
genericConfig
.
LoadGenericReferenceConfig
(
"getUser-generic"
)
time
.
Sleep
(
3
*
time
.
Second
)
resp
,
err
:=
genericConfig
.
GetService
()
.
Invoke
([]
interface
{}{
"GetUser"
,
[]
string
{
"java.lang.String"
},
[]
hessian
.
Object
{
"A003"
}})
if
err
!=
nil
{
panic
(
err
)
}
fmt
.
Println
(
"get resp:"
,
resp
)
}
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