func (ch *ConnectionHost) AddAckChannel() {
	ch.ackChanRWLock.Lock()
	defer ch.ackChanRWLock.Unlock()
	ch.ackChannelCount++
}
AddAckChannel increments the count of currentChannels
package pools
import (
	"crypto/tls"
	"errors"
	"sync"
	"time"
	"github.com/streadway/amqp"
)
type ConnectionHost struct {
	Connection         *amqp.Connection
	ConnectionID       uint64
	maxChannelCount    uint64
	maxAckChannelCount uint64
	channelCount       uint64
	ackChannelCount    uint64
	closeErrors        chan *amqp.Error
	chanRWLock         *sync.RWMutex
	ackChanRWLock      *sync.RWMutex
}
func NewConnectionHost(
	uri string,
	connectionName string,
	connectionID uint64,
	heartbeat time.Duration,
	connectionTimeout time.Duration,
	maxChannel uint64,
	maxAckChannelCount uint64) (*ConnectionHost, error) {
	var amqpConn *amqp.Connection
	var err error
	amqpConn, err = amqp.DialConfig(uri, amqp.Config{
		Heartbeat: heartbeat,
		Dial:      amqp.DefaultDial(connectionTimeout),
		Properties: amqp.Table{
			"connection_name": connectionName,
		},
	})
	if err != nil {
		return nil, err
	}
	connectionHost := &ConnectionHost{
		Connection:         amqpConn,
		ConnectionID:       connectionID,
		closeErrors:        make(chan *amqp.Error, 1),
		chanRWLock:         &sync.RWMutex{},
		ackChanRWLock:      &sync.RWMutex{},
		maxChannelCount:    maxChannel,
		maxAckChannelCount: maxAckChannelCount,
	}
	connectionHost.Connection.NotifyClose(connectionHost.closeErrors)
	return connectionHost, nil
}
func NewConnectionHostWithTLS(
	certServerName string,
	connectionName string,
	connectionID uint64,
	heartbeat time.Duration,
	connectionTimeout time.Duration,
	maxChannel uint64,
	maxAckChannelCount uint64,
	tlsConfig *tls.Config) (*ConnectionHost, error) {
	var amqpConn *amqp.Connection
	var err error
	amqpConn, err = amqp.DialConfig("amqps://"+certServerName, amqp.Config{
		Heartbeat:       heartbeat,
		Dial:            amqp.DefaultDial(connectionTimeout),
		TLSClientConfig: tlsConfig,
		Properties: amqp.Table{
			"connection_name": connectionName,
		},
	})
	if err != nil {
		return nil, err
	}
	connectionHost := &ConnectionHost{
		Connection:      amqpConn,
		ConnectionID:    connectionID,
		closeErrors:     make(chan *amqp.Error, 1),
		chanRWLock:      &sync.RWMutex{},
		ackChanRWLock:   &sync.RWMutex{},
		maxChannelCount: maxChannel,
	}
	connectionHost.Connection.NotifyClose(connectionHost.closeErrors)
	return connectionHost, nil
}
func (ch *ConnectionHost) CloseErrors() <-chan *amqp.Error {
	return ch.closeErrors
}
func (ch *ConnectionHost) CanAddChannel() bool {
	ch.chanRWLock.RLock()
	defer ch.chanRWLock.RUnlock()
	return ch.channelCount < ch.maxChannelCount
}
func (ch *ConnectionHost) AddChannel() {
	ch.chanRWLock.Lock()
	defer ch.chanRWLock.Unlock()
	ch.channelCount++
}
func (ch *ConnectionHost) RemoveChannel() error {
	ch.chanRWLock.Lock()
	defer ch.chanRWLock.Unlock()
	if ch.channelCount == 0 {
		return errors.New("can't remove any more channels from this connection host")
	}
	ch.channelCount--
	return nil
}
func (ch *ConnectionHost) CanAddAckChannel() bool {
	ch.ackChanRWLock.RLock()
	defer ch.ackChanRWLock.RUnlock()
	return ch.ackChannelCount < ch.maxAckChannelCount
}