forked from weibocom/motan-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientdemo.go
46 lines (40 loc) · 1.12 KB
/
clientdemo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"github.com/weibocom/motan-go"
motancore "github.com/weibocom/motan-go/core"
)
func main() {
runClientDemo()
}
func runClientDemo() {
mccontext := motan.GetClientContext("./clientdemo.yaml")
mccontext.Start(nil)
mclient := mccontext.GetClient("mytest-motan2")
args := make(map[string]string, 16)
args["name"] = "ray"
args["id"] = "xxxx"
var reply string
err := mclient.Call("hello", []interface{}{args}, &reply)
if err != nil {
fmt.Printf("motan call fail! err:%v\n", err)
} else {
fmt.Printf("motan call success! reply:%s\n", reply)
}
// async call
args["key"] = "test async"
result := mclient.Go("hello", []interface{}{args}, &reply, make(chan *motancore.AsyncResult, 1))
res := <-result.Done
if res.Error != nil {
fmt.Printf("motan async call fail! err:%v\n", res.Error)
} else {
fmt.Printf("motan async call success! reply:%+v\n", reply)
}
mclient2 := mccontext.GetClient("mytest-demo")
err = mclient2.Call("hello", []interface{}{"Ray"}, &reply)
if err != nil {
fmt.Printf("motan call fail! err:%v\n", err)
} else {
fmt.Printf("motan call success! reply:%s\n", reply)
}
}