-
Notifications
You must be signed in to change notification settings - Fork 1
/
_main.go
50 lines (43 loc) · 1.09 KB
/
_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
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"github.com/promisefemi/grpc-client-pooling/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"log"
"time"
)
func main() {
poolConfig := &grpc_pooling.PoolConfig{
MaxOpenConnection: 10,
MaxIdleConnection: 5,
ConnectionQueueLength: 10000,
NewClientDuration: time.Second * 5,
Address: ":9000",
ConfigOptions: []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
},
}
connPool := grpc_pooling.NewClientPool(poolConfig)
for {
client, err := connPool.Get()
if err != nil {
log.Fatalf("%s", err)
}
userMessage := &proto.UserMessage{
FirstName: "Promise",
LastName: "Femi",
Email: "",
}
uc := proto.NewUserClient(client.Conn)
response, err := uc.Set(context.Background(), userMessage)
if err != nil {
fmt.Printf("error unable to set user -- %s -- %d\n", err, connPool.GetNumberOfOpenConnections())
} else {
fmt.Printf("%+v -- %d \n", response, connPool.GetNumberOfOpenConnections())
}
client.Release()
}
}