Skip to content

dudebing99/grpc-connection-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usage

go get github.com/dudebing99/grpc-connection-pool

Example

package main

import (
	"context"
	"fmt"
	rpc "github.com/dudebing99/grpc-connection-pool"
)

func main() {
	pool, err := rpc.NewRpcClientPool(rpc.WithServerAddr("0.0.0.0:8080"))
	if err != nil {
		fmt.Println("init client pool error")
		return
	}

	clientConn, close, err := pool.Acquire()
	defer close()
	if err != nil {
		fmt.Println("acquire client connection error")
		return
	}

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	reply, err := NewGreeterClient(clientConn).SayHello(ctx, &HelloRequest{Name: "SillyBoy"})
	if err != nil {
		fmt.Println("say hello error, ", err)
		return
	}

	fmt.Println(reply.Message)
}