func (cp *ConnectionPool) GetTransientChannel(ackable bool) (*amqp.Channel, error) {
	for {
		connHost, err := cp.GetConnection()
		if err != nil {
			log.Error(cp.logger, "error occurered getting connection for transient channel", "err", err)
			continue
		}
		channel, err := connHost.Connection.Channel()
		if err != nil {
			log.Error(cp.logger, "error occurered creating channel for transient channel", "err", err)
			cp.ReturnConnection(connHost)
			continue
		}
		cp.ReturnConnection(connHost)
		if ackable {
			err := channel.Confirm(false)
			if err != nil {
				log.Error(cp.logger, "error occurered creating ackable channel for transient channel", "err", err)
				continue
			}
		}
		return channel, nil
	}
}
GetTransientChannel allows you create an unmanaged amqp Channel with the help of the ConnectionPool.
package rabbitmq
import (
	"strconv"
	"sync"
	"time"
	"github.com/pinpt/go-common/v10/log"
	"github.com/streadway/amqp"
)
type ConnectionPool struct {
	logger                   log.Logger
	name                     string
	uri                      string
	initialConnectionCount   int
	maxChannelsPerConnection int
	connections              chan *ConnectionHost
	publisherchannels        chan *ChannelHost
	connectionID             uint64
	poolRWLock               *sync.RWMutex
	flaggedConnections       map[uint64]bool
}
func NewConnectionPool(logger log.Logger, baseConnectionName, uri string, connections, channelsPerConnection int) (*ConnectionPool, error) {
	cp := &ConnectionPool{
		logger:                   logger,
		name:                     baseConnectionName,
		uri:                      uri,
		initialConnectionCount:   connections,
		maxChannelsPerConnection: channelsPerConnection,
		connections:              make(chan *ConnectionHost, 2000),  
		publisherchannels:        make(chan *ChannelHost, 5000),
		poolRWLock:               &sync.RWMutex{},
	}
	if err := cp.initializeConnections(); err != nil {
		return nil, err
	}
	return cp, nil
}
func (cp *ConnectionPool) createConnection(id int) (*ConnectionHost, error) {
	return NewConnectionHost(
		cp.logger,
		cp.uri,
		cp.name+"-"+strconv.Itoa(id))
}
func (cp *ConnectionPool) initializeConnections() error {
	for i := 0; i < cp.initialConnectionCount; i++ {
		connection, err := cp.createConnection(i)
		if err != nil {
			return err
		}
		cp.connections <- connection
	}
	return nil
}
func (cp *ConnectionPool) GetConnection() (*ConnectionHost, error) {
	cp.poolRWLock.RLock()
	conns := cp.connections
	cp.poolRWLock.RUnlock()
	maxcount := len(conns)
	i := 0
	for {
		if i == maxcount {
			log.Debug(cp.logger, "no free connection, creating new one")
			break
		}
		select {
		case conn := <-conns:
			if conn.CanTakeMoreChannels(cp.maxChannelsPerConnection) {
				return conn, nil
			}
			cp.connections <- conn
		default:
			break
		}
		i++
	}
	log.Debug(cp.logger, "creating new channel")
	conn, err := cp.createConnection(int(time.Now().Unix() * 1000))
	if err != nil {
		return nil, err
	}
	return conn, nil
}
func (cp *ConnectionPool) ReturnConnection(connHost *ConnectionHost) {
	select {
	case cp.connections <- connHost:
		log.Debug(cp.logger, "returning connection")
	default:
		log.Debug(cp.logger, "closing connection")
		connHost.Connection.Close()
	}
}
func (cp *ConnectionPool) GetChannel() (*ChannelHost, error) {
	return cp.createChannel()
}
func (cp *ConnectionPool) ReturnChannel(chanHost *ChannelHost, erred bool) {
	chanHost.Close()
}
func (cp *ConnectionPool) createChannel() (*ChannelHost, error) {
	for {
		connHost, err := cp.GetConnection()
		log.Debug(cp.logger, "Got a connection to add a channel to")
		if err != nil || connHost.Connection.IsClosed() {
			log.Error(cp.logger, "error getting connection to create channel", "err", err)
			time.Sleep(reconnectDelay)
			continue
		}
		chanHost, err := NewChannelHost(cp.logger, connHost, true)
		log.Debug(cp.logger, "Got a new channel")
		if err != nil {
			log.Error(cp.logger, "error creating channel", "err", err)
			continue
		}
		log.Debug(cp.logger, "try to return connection")
		cp.ReturnConnection(connHost)
		log.Debug(cp.logger, "Returning connection")
		return chanHost, nil
	}
}
func (cp *ConnectionPool) getPublisherChannel() (*ChannelHost, error) {
	select {
	case publisher := <-cp.publisherchannels:
		log.Debug(cp.logger, "got publisher channel from pool")
		return publisher, nil
	default:
		log.Debug(cp.logger, "pool exhausted, creating publisher channel")
		publisher, err := cp.GetChannel()
		return publisher, err
	}
}
func (cp *ConnectionPool) returnPublisherChannel(publisher *ChannelHost) {
	select {
	case cp.publisherchannels <- publisher:
		log.Debug(cp.logger, "putting publisher channel")
	default:
		publisher.Close()
	}
}