/
order.go
33 lines (26 loc) · 974 Bytes
/
order.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
package clients
import (
"log"
"time"
"github.com/drhelius/grpc-demo-proto/order"
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
"github.com/opentracing/opentracing-go"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
var OrderService order.OrderServiceClient
func init() {
log.Printf("[Account] Dialing to 'order:5000' ...")
keepAliveParams := keepalive.ClientParameters{
Time: 5 * time.Second,
Timeout: time.Second,
PermitWithoutStream: true,
}
conn, err := grpc.Dial("order:5000", grpc.WithInsecure(), grpc.WithBlock(), grpc.FailOnNonTempDialError(true), grpc.WithKeepaliveParams(keepAliveParams), grpc.WithStreamInterceptor(
grpc_opentracing.StreamClientInterceptor(
grpc_opentracing.WithTracer(opentracing.GlobalTracer()))))
if err != nil {
log.Fatalf("[Account] Error dialing to Order service: %v", err)
}
OrderService = order.NewOrderServiceClient(conn)
}