Skip to content
forked from flyaways/pool

General Purpose Connection Pool for GRPC,RPC,TCP Sevice Cluster. add life cycle

License

Notifications You must be signed in to change notification settings

GitHub121380/pool

 
 

Repository files navigation

Pool

GoDoc Go Report Card Build Status Travis Build Status Semaphore Sourcegraph Open Source Helpers LICENSE GitHub code size in bytes Release LICENSE

Pool is Used to manage and reuse client connections to service cluster.

Pool provides several key features:

  • General Purpose - Pool for GRPC,RPC,TCP.support RPC timeout.

  • Support Cluster - Connet to Cluster.

  • Danamic Update - Danamic update targets.

Pool runs on Linux, Mac OS X, and Windows.

Note: Random to pick a target to get one connection for loadbalance.

Install

go get -u github.com/GitHub121380/pool

Usage

import "github.com/GitHub121380/pool"

Example

package main

import (
	"log"
	"time"

	"github.com/GitHub121380/pool"
	"google.golang.org/grpc"
)

func main() {
	options := &pool.Options{
		InitTargets: []string{"127.0.0.1:8080"},
		InitCap:     5,
		MaxCap:      30,
		TimeoutType: pool.IdleTimeoutType,
		//TimeoutType:  pool.FixedTimeoutType,
		DialTimeout:  time.Second * 5,
		IdleTimeout:  time.Second * 60,
		ReadTimeout:  time.Second * 5,
		WriteTimeout: time.Second * 5,
	}

	p, err := pool.NewGRPCPool(options, grpc.WithInsecure()) //for grpc
	//p, err := pool.NewRPCPool(options) 			//for rpc
	//p, err := pool.NewTCPPool(options)			//for tcp

	if err != nil {
		log.Printf("%#v\n", err)
		return
	}

	if p == nil {
		log.Printf("p= %#v\n", p)
		return
	}

	defer p.Close()

	//todo
	//danamic update targets
	//options.Input()<-&[]string{}

	conn, err := p.Get()
	if err != nil {
		log.Printf("%#v\n", err)
		return
	}

	defer p.Put(conn)

	//todo
	//conn.DoSomething()

	log.Printf("len=%d\n", p.IdleCount())
}

Reference

Contribution Welcomed !

Contributors

About

General Purpose Connection Pool for GRPC,RPC,TCP Sevice Cluster. add life cycle

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%