connpool

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed performs any operation on the closed publisher will return this error.
	ErrClosed = errors.New("amqp: connection pool is closed")

	// ErrPoolTimeout timed out waiting to get a connection from the connection pool.
	ErrPoolTimeout = errors.New("amqp: connection pool timeout")
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func NewConn

func NewConn(amqpConn *amqp.Connection, amqpCh *amqp.Channel) *Conn

func (*Conn) Channel

func (c *Conn) Channel() *amqp.Channel

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

func (*Conn) NotifyClose

func (c *Conn) NotifyClose(receiver chan *amqp.Error) chan *amqp.Error

func (*Conn) SetUsedAt

func (c *Conn) SetUsedAt(tm time.Time)

func (*Conn) UsedAt

func (c *Conn) UsedAt() time.Time

type ConnPool

type ConnPool struct {
	// contains filtered or unexported fields
}

func New

func New(opt *Options) *ConnPool

func (*ConnPool) Close

func (p *ConnPool) Close() error

func (*ConnPool) CloseConn

func (p *ConnPool) CloseConn(cn *Conn) error

func (*ConnPool) Filter

func (p *ConnPool) Filter(fn func(*Conn) bool) error

func (*ConnPool) Get

func (p *ConnPool) Get(ctx context.Context) (*Conn, error)

Get returns existed connection from the pool or creates a new one.

func (*ConnPool) IdleLen

func (p *ConnPool) IdleLen() int

IdleLen returns number of idle connections.

func (*ConnPool) Len

func (p *ConnPool) Len() int

Len returns total number of connections.

func (*ConnPool) NewConn

func (p *ConnPool) NewConn() (*Conn, error)

func (*ConnPool) Put

func (p *ConnPool) Put(ctx context.Context, cn *Conn)

func (*ConnPool) ReapStaleConns

func (p *ConnPool) ReapStaleConns() (int, error)

func (*ConnPool) Remove

func (p *ConnPool) Remove(ctx context.Context, cn *Conn, reason error)

func (*ConnPool) Stats

func (p *ConnPool) Stats() *Stats

type Options

type Options struct {
	Dialer             func() (*amqp.Connection, *amqp.Channel, error)
	OnClose            func(*Conn) error
	PoolFIFO           bool
	PoolSize           int
	MinIdleConns       int
	MaxConnAge         time.Duration
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
}

type Pooler

type Pooler interface {
	NewConn() (*Conn, error)
	CloseConn(*Conn) error

	Get(context.Context) (*Conn, error)
	Put(context.Context, *Conn)
	Remove(context.Context, *Conn, error)

	Len() int
	IdleLen() int
	Stats() *Stats

	Close() error
}

type Stats

type Stats struct {
	Hits     uint32 // number of times free connection was found in the pool
	Misses   uint32 // number of times free connection was NOT found in the pool
	Timeouts uint32 // number of times a wait timeout occurred

	TotalConns uint32 // number of total connections in the pool
	IdleConns  uint32 // number of idle connections in the pool
	StaleConns uint32 // number of stale connections removed from the pool
}

Stats contains pool state information and accumulated stats.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL