Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
a615e175
Commit
a615e175
authored
Oct 18, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Imp: add micro CallOneway/AsyncCall
parent
a7eaa4af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
8 deletions
+38
-8
change_log.md
change_log.md
+1
-1
client.go
micro/client.go
+37
-7
No files found.
change_log.md
View file @
a615e175
...
...
@@ -16,7 +16,7 @@
-
2018/10/16
> Feature
*
add CallOneway/AsyncCall
*
add
rpc/micro
CallOneway/AsyncCall
*
version: v1.0.3
-
2018/08/19
...
...
micro/client.go
View file @
a615e175
...
...
@@ -155,15 +155,15 @@ func NewClient(conf *rpc.ClientConfig, regConf *ConsumerRegistryConfig, opts ...
return
clt
,
nil
}
func
(
c
*
Client
)
Call
(
ctx
context
.
Context
,
typ
rpc
.
CodecType
,
service
,
version
,
method
string
,
args
interface
{},
reply
interface
{},
opts
...
rpc
.
CallOption
)
error
{
func
(
c
*
Client
)
getServiceAddr
(
ctx
context
.
Context
,
typ
rpc
.
CodecType
,
service
,
version
string
)
(
string
,
error
)
{
attr
:=
c
.
attr
attr
.
Service
=
service
attr
.
Protocol
=
typ
.
String
()
attr
.
Role
=
gxregistry
.
SRT_Provider
attr
.
Version
=
version
var
addr
string
flag
:=
false
svcArray
,
ok
:=
c
.
svcMap
[
attr
]
if
!
ok
{
...
...
@@ -176,7 +176,7 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, version,
if
flag
{
var
err
error
if
svcArray
,
err
=
c
.
filter
.
Filter
(
attr
);
err
!=
nil
{
return
jerrors
.
Trace
(
err
)
return
addr
,
jerrors
.
Trace
(
err
)
}
c
.
svcMap
[
attr
]
=
svcArray
...
...
@@ -184,18 +184,48 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, version,
svc
,
err
:=
svcArray
.
Select
(
ctx
,
c
.
ClientOptions
.
hash
)
if
err
!=
nil
{
return
jerrors
.
Trace
(
err
)
return
addr
,
jerrors
.
Trace
(
err
)
}
if
len
(
svc
.
Nodes
)
!=
1
{
return
jerrors
.
Errorf
(
"illegal service %#v"
,
svc
)
return
addr
,
jerrors
.
Errorf
(
"illegal service %#v"
,
svc
)
}
addr
:=
gxnet
.
HostAddress
(
svc
.
Nodes
[
0
]
.
Address
,
int
(
svc
.
Nodes
[
0
]
.
Port
))
return
gxnet
.
HostAddress
(
svc
.
Nodes
[
0
]
.
Address
,
int
(
svc
.
Nodes
[
0
]
.
Port
)),
nil
}
func
(
c
*
Client
)
CallOneway
(
ctx
context
.
Context
,
typ
rpc
.
CodecType
,
service
,
version
,
method
string
,
args
interface
{},
opts
...
rpc
.
CallOption
)
error
{
addr
,
err
:=
c
.
getServiceAddr
(
ctx
,
typ
,
service
,
version
)
if
err
!=
nil
{
return
jerrors
.
Trace
(
err
)
}
return
jerrors
.
Trace
(
c
.
Client
.
CallOneway
(
typ
,
addr
,
service
,
method
,
args
,
opts
...
))
}
func
(
c
*
Client
)
Call
(
ctx
context
.
Context
,
typ
rpc
.
CodecType
,
service
,
version
,
method
string
,
args
interface
{},
reply
interface
{},
opts
...
rpc
.
CallOption
)
error
{
addr
,
err
:=
c
.
getServiceAddr
(
ctx
,
typ
,
service
,
version
)
if
err
!=
nil
{
return
jerrors
.
Trace
(
err
)
}
return
jerrors
.
Trace
(
c
.
Client
.
Call
(
typ
,
addr
,
service
,
method
,
args
,
reply
,
opts
...
))
}
func
(
c
*
Client
)
AsyncCall
(
ctx
context
.
Context
,
typ
rpc
.
CodecType
,
service
,
version
,
method
string
,
args
interface
{},
callback
rpc
.
AsyncCallback
,
reply
interface
{},
opts
...
rpc
.
CallOption
)
error
{
addr
,
err
:=
c
.
getServiceAddr
(
ctx
,
typ
,
service
,
version
)
if
err
!=
nil
{
return
jerrors
.
Trace
(
err
)
}
return
jerrors
.
Trace
(
c
.
Client
.
AsyncCall
(
typ
,
addr
,
service
,
method
,
args
,
callback
,
reply
,
opts
...
))
}
func
(
c
*
Client
)
Close
()
{
c
.
filter
.
Close
()
c
.
registry
.
Close
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment