forked from T-J-L/nrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 795 Bytes
/
main.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
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/nats-io/nats.go"
// This is the package containing the generated *.pb.go and *.nrpc.go
// files.
"github.com/ftamhar/nrpc/examples/helloworld/helloworld"
)
func main() {
natsURL := nats.DefaultURL
if len(os.Args) == 2 {
natsURL = os.Args[1]
}
// Connect to the NATS server.
nc, err := nats.Connect(natsURL, nats.Timeout(5*time.Second))
if err != nil {
log.Fatal(err)
}
defer nc.Close()
// This is our generated client.
cli := helloworld.NewGreeterClient(nc)
// Contact the server and print out its response.
resp, err := cli.SayHello(context.Background(), &helloworld.HelloRequest{Name: "world"})
if err != nil {
log.Fatal(err)
}
// print
fmt.Printf("Greeting: %s\n", resp.GetMessage())
}