Skip to content

Latest commit

 

History

History
111 lines (79 loc) · 3.01 KB

README.md

File metadata and controls

111 lines (79 loc) · 3.01 KB

Pool

GoDoc Go Report Card 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 gopkg.in/flyaways/pool.v1

Usage

import "gopkg.in/flyaways/pool.v1"

Example

package main

import (
	"log"
	"time"

	"gopkg.in/flyaways/pool.v1"
	"google.golang.org/grpc"
)

func main() {
	options := &pool.Options{
		InitTargets:  []string{"127.0.0.1:8080"},
		InitCap:      5,
		MaxCap:       30,
		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

License

  • The MIT License (MIT) - see LICENSE for more details

FOSSA Status